C # Programming (24)----------modifiers

Source: Internet
Author: User
Tags modifiers

Modifier

Modifiers are keywords that apply to types or members . Modifiers can specify the visibility of a method , such as public or private, and you can specify the nature of an item , such as a vritual or abstract that has just been sent.

Modifiers for visibility

Modifier

Applied to

Description

Public

All types or members

Any code can access the item

Protected

All members of type and inline type

Only derived types can access the item

Internal

All types or members

The item can only be accessed in the assembly that contains it

Private

All members of type and inline type

The item can only be accessed in the type to which it belongs

protected internal

All members of type and inline type

The item can only be accessed in any code that contains his assembly and derived types

Note that the definition of a class can only be internal or public , depending on whether you want to access it outside of the assembly that the type contains :

public class MyClass

{}

The type cannot be declared asProtected,private,Andprotected internal, Because these modifiers have no meaning for the types contained in the namespace . So these modifiers can only be applied with members . But , You can use these modifiers to define nested types (, contains types because in this case , Type also has member status . So the following code is legal :

public class Outerclass

{

Protected class Innerclass

{}

}

If there is a nested type , the internal type always has access to all members of the external type . So , in the code above,the code in Innerclass can access all members of the Outerclass , and even the private members of Outerclass can access .

Other modifiers

Modifier

Applied to

Description

New

Function members

Members with the same signature hide inherited members

Static

All Members

Members do not make specific instances of the class

Vritual

Function Members Only

Members can be overridden by derived classes

Abstract

Gold function member

The virtual member defines the signature of the member and does not provide the implementation code

Override

Function Members Only

A member overrides an inherited virtual or abstract member

Sealed

Classes , methods, and properties

For classes , you cannot inherit from a sealed class . For properties and Methods , a member overrides an inherited virtual member , but no member of any derived class can override the school-constant source . The modifier must be used with override

extern

static method only

Members are externally implemented in the Ning Yizhong language .

C # Programming (24)----------modifiers

Related Article

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.