C#中static类型的变量和方法.doc
上传者:蓝天
2022-06-03 15:13:50上传
DOC文件
84 KB
C#中static类型的变量和方法
Variables and methods of type C# in static
define variables and methods, and do not know when to add the static modifier.
What are the differences between static variables and methods and non static variables and methods?
in a static method of class, why can't you access non static member variables and methods of this class?
why can you access static variables and methods of that class in a class of non static methods?
Why can't this be used in static methods?
what's the role of static constructors?
Based on the above questions, I have expressed my views as follows:
static variables and methods do not instantiate objects, you can use class names, static variables, and class names. Static methods are accessed in this way, which makes access more convenient without manually instantiating objects. For some read-only variables and methods, it's good for sharing.
static and non static the biggest difference is that the static type variables and methods, when the call is allocated in memory address, and this address is only one, so static can be accessed directly. Instead of static, you must instantiate the class manually to access variables and methods in the form of objects.
in a static method to access the class non static variables or methods, because static belongs to the class itself, is called the time in class, static type has been generated,
Variables and methods of type C# in static
define variables and methods, and do not know when to add the static modifier.
What are the differences between static variables and methods and non static variables and methods?
in a static method of class, why can't you access non static member variables and methods of this class?
why can you access static variables and methods of that class in a class of non static methods?
Why can't this be used in static methods?
what's the role of static constructors?
Based on the above questions, I have expressed my views as follows:
static variables and methods do not instantiate objects, you can use class names, static variables, and class names. Static methods are accessed in this way, which makes access more convenient without manually instantiating objects. For some read-only variables and methods, it's good for sharing.
static and non static the biggest difference is that the static type variables and methods, when the call is allocated in memory address, and this address is only one, so static can be accessed directly. Instead of static, you must instantiate the class manually to access variables and methods in the form of objects.
in a static method to access the class non static variables or methods, because static belongs to the class itself, is called the time in class, static type has been generated,
C#中static类型的变量和方法