当前位置:网站首页>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边栏推荐
- Add automatic model generation function to hade
- How to select the minimum and maximum values of columns in the data table- How to select min and max values of a column in a datatable?
- Strategy application of Dameng database
- sql server数据库添加 mdf数据库文件,遇到的报错
- [C language] MD5 encryption for account password
- 【翻译】后台项目加入了CNCF孵化器
- [principles of multithreading and high concurrency: 1_cpu multi-level cache model]
- 【翻译】Flux安全。通过模糊处理获得更多信心
- Can netstat still play like this?
- Use cve-2021-43893 to delete files on the domain controller
猜你喜欢
HW initial preparation
What does "where 1=1" mean
Error invalid bound statement (not found): com ruoyi. stock. mapper. StockDetailMapper. XXXX solution
Can netstat still play like this?
sql server数据库添加 mdf数据库文件,遇到的报错
[translation] the background project has joined the CNCF incubator
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]
Segmentation fault occurs during VFORK execution
Your family must be very poor if you fight like this!
SqlServer行转列PIVOT
随机推荐
SqlServer行转列PIVOT
【翻译】后台项目加入了CNCF孵化器
Error when installing MySQL in Linux: starting mysql The server quit without updating PID file ([FAILED]al/mysql/data/l.pid
MATLAB小技巧(24)RBF,GRNN,PNN-神经网络
Thunderbolt Chrome extension caused the data returned by the server JS parsing page data exception
[fluent] future asynchronous programming (introduction | then method | exception capture | async, await keywords | whencomplete method | timeout method)
Baidu map - surrounding search
Gbase 8C system table PG_ amproc
Le processus de connexion mysql avec docker
js根据树结构查找某个节点的下面的所有父节点或者子节点
Three.js本地环境搭建
Practice of traffic recording and playback in vivo
Hcip137-147 title + analysis
Wechat - developed by wechat official account Net core access
Chart. JS multitooltip tag - chart js multiTooltip labels
Yiwen takes you to know ZigBee
Cron表达式介绍
Build a private cloud disk cloudrev
Basic operation of binary tree (C language version)
Use cve-2021-43893 to delete files on the domain controller