In the case of instance syntax to access the error of static members
In C#, when trying to use examples to access static members, they will encounter an error "member"
"cannot use instances to reference access". To solve this problem, you must understand the difference between static members and instance members.
Static members use the keyword "Static" statement, which is associated with the type itself, not associated with any instance of the type. They are shared between all instances and can be accessed without instantiated objects. In example members
Example members declare without the "static" keyword and are associated with a specific instance. They can only be accessed through type instances.
Problem explanation
In a given code example,
Myitem.property1is a static member because it uses the "STATIC" keyword declaration. Therefore, it cannot be used to access it ( OITEM.PROPERTY1 ).
Solution To access the static members myitem.property1
, you can choose the following two methods:Limited members of the type name:
This will change the member from a static member to an instance member, allowing you to use example syntax to access it.
The above is the detailed content of Why Can't I Access a Static Member Using Instance Syntax in C#?. For more information, please follow other related articles on the PHP Chinese website!