Calls to static members and non-static members in C #

Source: Internet
Author: User
Tags execution instance method
Static

Static and non-static problems should be found on the Internet to find some information, the following is the collation of some information.

The existence of a non-static member depends on the instance, so it can also be called an instance member.

The members in the class include:

Data members:
Data members can be divided into static variables, instance variables and two.
Static members: Static member variables are associated with the class, can be used as a "total" in the class variable (is a common expression), he does not rely on the existence of a particular object, access by the class name dot operation alphanumeric variable name to access.
Instance member: an instance member variable is associated with an object, and accessing the instance member variable depends on the existence of the instance.

Function Members:
Methods can be mainly divided into static methods, instance methods
Static method: Static method is not a specific object of the method, static methods can access static member variables, static methods can not directly access the instance variables, can be in the case of the instance function call, the instance variable as a parameter passed to the static method. Static methods also cannot call instance methods directly, and can be called indirectly by first creating an instance of a class and then invoking the instance method through this particular object, but the static method can be invoked.
Instance method: The execution of an instance method is associated with a particular object, and his execution requires an object to exist. Instance methods can directly access static variables and instance variables, instance methods can directly access instance method, and static method, static method access way for class name dot operation alphanumeric variable name. When multiple instance objects exist, there is not a copy of the US-specific instance method in memory, but all objects of the same class share a copy of each instance method (the instance method takes up only "set" space).



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.