C # Fundamentals (ii)

Source: Internet
Author: User

1. Scope modifier modifier:

Public: Common access, that is, members of the owning class and members of the non-owning class can access

Private access: Only members of the owning class can access the

Internal: Internal access, only the current assembly can access

Protected: Protected Access, the type of the owning subclass and parent class can be accessed

2. Static variable statics

Static variables do not disappear after the function is executed, and their values are preserved throughout the program.

A static variable can be initialized outside of a member function or a class definition.

For all objects of a class, only one copy of the static variable exists in memory and cannot be instantiated.

Because there is no instance variable, you use the class name itself to access the members of the static class.

You can get the value of a static variable without creating an instance of the class

If you apply the static keyword to a class, all members of the class must be static.

3. Constructor function

Instance constructors: Instance constructors are called when an instance of a class is created.  These constructors are used to initialize class data members.           Static constructors: Static constructors are used to initialize static variables of a class. These variables are created using the static keyword, and the values they store can be shared by all instances of the class.

C # Fundamentals (ii)

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.