Disable/suppress warning CS0649 in C# for a specific field of class

前端 未结 5 2067
春和景丽
春和景丽 2020-12-18 17:54

I have some fields in a C# class which I initialize using reflection. The compiler shows CS0649 warning for them:

Field foo\' is never assigned

5条回答
  •  暖寄归人
    2020-12-18 18:18

    I believe it's worth noting the warning can also be suppressed by using inline initialization. This clutters your code much less.

    public class MyClass
    {
        // field declarations for which to disable warning
        private object foo = null;
    
        // rest of class
    }
    

提交回复
热议问题