C # Learning Note---modifiers, this keyword and the static keyword

Source: Internet
Author: User

1. Modifiers for classes in C #:

public means that access to the class is not restricted

protected means that access can only be made from subclasses that are derived from the class and the class in which they reside

private only the class in which it is located can access

internal only access to applications or libraries in a package

abstract class does not allow an instance of a class to be established

sealed sealed class is not allowed to be inherited

The definition of the protected modifier has changed compared to Java. The addition of internal in C # is similar to the definition of protected in Java. The sealed modifier is similar to the definition of final class in Java.

2. The This keyword in C # (similar to Java)

The reserved word this is limited to using the constructor class's methods and instances of the class to have the following meanings

1. This appears in the constructor of the class as a value type that represents a reference to the object being constructed

2. This occurs in the method of the class as a value type that represents a reference to the object that called the method

3. This occurs in the constructor of the struct as a variable type that represents a reference to the structure being constructed

4. This appears in the method of the struct as a variable type it represents a reference to the struct that called the method

In summary, this always represents a reference to the current object .

3. Static and non-static members in C #

If a member in a class is declared as static, the member is called a statics member. In general, static members are owned by the class, and non-static members belong to the instance of the class, which is all of the objects.

A non-static member of a class belongs to an instance of the class, and each instance that creates a class opens an area in memory for non-static members. A static member of a class is owned by the class and is shared by all instances of the class, regardless of how many copies the class creates, and a static member occupies only one area of memory.

C # Learning Note---modifiers, this keyword and the static keyword

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.