What is a “static” class?

后端 未结 10 1434
面向向阳花
面向向阳花 2020-12-04 16:35

In C# what is the difference between:

public static class ClassName {}

And:

public class ClassName {}
10条回答
  •  一向
    一向 (楼主)
    2020-12-04 17:16

    public static class ClassName {}
    

    A static class is just like a global variable: you can use it anywhere in your code without instantiating them. For example: ClassName. After the dot operator, you can use any property or function of it.

     public class ClassName {}
    

    But if you have non-static class then you need to create an instance of this class. For example:

     ClassName classNameObject = new ClassName(); 
    

提交回复
热议问题