Static and static class members

Source: Internet
Author: User

Static and static class members are used to create data and functions that can be accessed without the need to create instances of classes.

Static class members can be used to separate data and behavior independent of any object identifier: No matter what changes occur to the object, the data and functions will not change. When the class does not depend on the data or behavior of object identifiers, you can use static classes.

Static class:

Static classes are declared using static statements and only contain static members. You cannot use the new keyword to create static class instances.

When a static class loads a program or namespace containing the class, it is automatically loaded by the. NET Framework Common Language Runtime Library (CLR.

Static classes are sealed and therefore cannot be inherited. A static class cannot contain constructor, but can still declare a static constructor to assign an initial value or set a static state.

Static members:

You can call static methods, fields, attributes, or events in the class even if no instance of the class is created. If any instance of this class is created, the instance cannot be used to access static members.

Static members are usually used to represent data or computing that does not change with the object state.

Static members are initialized before the first access and before any static Constructor (if called. To access a static class member, use the class name instead of the variable name to specify the position of the Member.

 

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.