询问者
文件操作问题--错误:字段初始值无法引用非静态字段。。。

问题
全部回复
-
Hi,
欢迎在MSDN论坛发帖。
你有把这个赋值操作放到一个方法体里面执行吗?
我这边测试,如果把赋值语句放到方法体里面,就没有出现这个问题,如果可以,你可以上传可以重现问题的代码到one drive上面吗? 这样方便测试, 我下面代码做了字段,属性的测试,你可以查看一下。希望对你有帮助。
class Program { public int i = 5; public int j = i; // CS0236 public int k; // initialize in constructor Program() { k = i; } public int ty { get; set; } = 4; public int te { get; set; } = ty; void test() { k = i; te = ty; } static void Main(string[] args) { int i = 5; int j = i; } }
Best Regards,
Hart
MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
-
-
Hi,
如果你的问题已经解决,请及时标记有用的回复作为答案,这样会帮助遇到相同问题的人。
Best Regards,
Hart
MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.