更新时间:2021-10-21 09:46:35
Visual Studio 2017(15.7.1)的最新更新现在为此提供了一个选项.在Tools->Options
菜单下,选择TextEditor->C#->Code Style->General
选项卡.在Field preferences
下,有一个Prefer readonly
选项.将其设置为No
.
A recent update to Visual Studio 2017 (15.7.1) has an option for this now. Under the Tools->Options
menu, select the TextEditor->C#->Code Style->General
tab. Under Field preferences
, there is a Prefer readonly
option. Set that to No
.
如果要在代码旁边检查此首选项,还可以设置editorconfig
设置,因此使用代码的其他人不会收到警告,但是必须针对每个解决方案进行设置基础.您将设置的editorconfig
值为:
There is also an editorconfig
setting you can set if you want to check this preference in along side your code, so others who consume your code don't get the warning, but that has to be done on a per solution basis. The editorconfig
value you would set would be:
dotnet_style_readonly_field = false:none