Why do I NOT get warnings about uninitialized readonly fields?

后端 未结 4 1819
醉酒成梦
醉酒成梦 2020-12-18 19:00

The C# compiler is kind enough to give you a \"field is never assigned to\" warning if you forget to initialize a readonly member which is private or internal, or if the cla

4条回答
  •  伪装坚强ぢ
    2020-12-18 19:44

    If it is public (or better not private) it can be used by another class outside your project. This is important to build libraries who should be used by others. If you would get a warning for every not used public property, field or method you wouldn't see the real problems.

提交回复
热议问题