Static classes in c#

前端 未结 8 713
别那么骄傲
别那么骄傲 2021-01-18 03:09

In answering this question (https://stackoverflow.com/questions/352317/c-coding-question#352327), it got me wondering...

Is there any danger in regarding a static cl

8条回答
  •  一整个雨季
    2021-01-18 03:47

    As Robert said before, the initialization is a main disadvantage of a static class. The static class will usually be initialized lazily, at the last possible moment. However, you lose control over the exact behavior and static constructors are slow.

    Often static classes are used to hold global data. And global data creates an implicit dependency between your other objects / classes. So you must be carful when changing this "global object". Can break your application.

提交回复
热议问题