static classes in C#

As I am a new C# programmer, but I programmed in Java for many years, I often use singleton pattern when I want to keep only one instance in a program. Today when I continue reading C# grammar, I suddenly find that static class can be a natural singleton.

You don't need to keep a static instance within the class, if the class is a static class, you can't create its instance. But you can keep static members. And you even can have a static constructor to initialize your static members if they are complex. Isn't this a best singleton?

I am not sure about it. I will try to use this feature to verify its performance.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章