当前位置:网站首页>Can I use read-only to automatically implement properties- Is read-only auto-implemented property possible?
Can I use read-only to automatically implement properties- Is read-only auto-implemented property possible?
2022-07-03 02:52:00 【Technology feast】
problem :
I found a topic on MSDN that talks that yes, this is possible. I am here MSDN Found a topic on , Yes , It's possible .
I did a test that seems to break this statement: I did a test that seemed to break this statement :
using System;namespace Test{ class Program { static void Main(string[] args) { Foo f = new Foo("1"); Console.WriteLine(f.Bar); // prints 1 f.Test("2"); Console.WriteLine(f.Bar);// successfully prints 2 } } class Foo { public Foo(string b) { this.Bar = b; } public string Bar { get; private set; } public void Test(string b) { // this would be impossible for readonly field! // next error would be occur: CS0191 or CS0191 // A readonly field cannot be assigned to (except in a constructor or a variable initializer) this.Bar = b; } }}
Where am I wrong? What's wrong with me ?
Solution :
Reference resources : https://stackoom.com/en/question/API7边栏推荐
- [fluent] futurebuilder asynchronous programming (futurebuilder construction method | asyncsnapshot asynchronous calculation)
- 处理数据集,使用LabelEncoder将所有id转换为从0开始
- What is the way out for children from poor families?
- [C语言]给账号密码进行MD5加密
- I2C 子系统(三):I2C Driver
- [translation] the background project has joined the CNCF incubator
- Why choose a frame? What frame to choose
- HW-初始准备
- 你真的懂继电器吗?
- HTB-Devel
猜你喜欢
I2C 子系统(二):I3C spec
搭建私有云盘 cloudreve
函数栈帧的创建与销毁
Xiaodi notes
Deep learning: multi-layer perceptron and XOR problem (pytoch Implementation)
[fluent] listview list (map method description of list set | vertical list | horizontal list | code example)
Classes and objects - initialization and cleanup of objects - constructor call rules
左连接,内连接
I2C 子系统(三):I2C Driver
Kubernetes cluster log and efk architecture log scheme
随机推荐
超好用的日志库 logzero
Basic operation of binary tree (C language version)
MATLAB小技巧(24)RBF,GRNN,PNN-神经网络
The left value and the right finger explain better
HW initial preparation
Apple releases MacOS 11.6.4 update: mainly security fixes
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]
The difference between left value and right value in C language
Practice of traffic recording and playback in vivo
Xiaodi notes
Thunderbolt Chrome extension caused the data returned by the server JS parsing page data exception
2022-2028 global splicing display industry research and trend analysis report
How to implement append in tensor
《MATLAB 神经网络43个案例分析》:第43章 神经网络高效编程技巧——基于MATLAB R2012b新版本特性的探讨
sql server 查询指定表的表结构
Getting started | jetpack hilt dependency injection framework
random shuffle注意
"Analysis of 43 cases of MATLAB neural network": Chapter 43 efficient programming skills of neural network -- Discussion Based on the characteristics of the new version of MATLAB r2012b
Didi programmers are despised by relatives: an annual salary of 800000 is not as good as two teachers
[translation] the background project has joined the CNCF incubator