Common C # keyword explanation tutorials,

Source: Internet
Author: User

Common C # keyword explanation tutorials,


Many back-end students are confused about the C # keywords. Now I will learn the meanings of these keywords with you.

Type

Void
When used as the return type of a method, the void keyword specifies that the method does not return a value.

Void is not allowed in the parameter list of the method. Declare a non-parametric, Non-Return Value Method in the following form:

Ovid SampleMethod ();

Var

Variables declared in the method range can have implicit type var. Implicit local variables are strongly typed (as if you have declared this type), but the type is determined by the compiler. Return Value


Reference Type

Class

Class is declared using the keyword class.


Delegate

The Declaration of the delegate type is similar to the method signature. There is a return value and any number of parameters of any type:
Public delegate void TestDelegate (string message );

Public delegate int TestDelegate (MyType m, long num );

Delegate is a reference type that can be used to encapsulate naming or anonymous methods. The delegate is similar to the function pointer in C ++. However, the delegate type is safe and reliable.

Interface

The interface only contains the signatures of methods, properties, events, or indexers. The member implementation is completed in the class or structure that implements the interface.

Object

The object type is the alias of the Object in. NET Framework. In the unified type system of C #, all types (pre-defined type, user-defined type, reference type and value type) are inherited directly or indirectly from the Object. Any type of value can be assigned to an object-type variable. The process of converting a value type variable to an object is called "Packing ". The process of converting an object type variable to a value type is called "unboxing ".

String

String represents a sequence composed of zero or more Unicode characters. String is the alias of String in. NET Framework.

Although string is a reference type, it defines equal operators (= and! =) Is to compare the value of a string object (rather than a reference. This makes the test of string equality more intuitive.
Www.51rgb.com

Modifier

Override

Override modifiers must be used to extend or modify the abstract or virtual Implementation of inherited methods, attributes, indexers, or events.

Virtual

Virtual keywords are used to modify methods, attributes, indexers, or event declarations, and enable them to be overwritten in a derived class. For example, this method can be overwritten by any class that inherits it.

Volatile

The volatile keyword indicates that a field can be modified by multiple concurrent threads. Fields declared as volatile are not restricted by Compiler Optimization (assuming that they are accessed by a single thread. This ensures that the field displays the latest value at any time.

Unsafe

The unsafe keyword indicates the insecure context, which is required for any operations involving pointers.

Static

Use the static modifier to declare a static member of a type rather than a specific object. Static modifiers can be used for classes, fields, methods, attributes, operators, events, and constructors, but cannot be used for types other than the indexer, destructor, or class.

Sealed

When the sealed modifier is applied to a class, this modifier prevents other classes from inheriting from the class. In the following example, Class B inherits from Class A, but no class can inherit from Class B.

Readonly

The readonly keyword is a modifier that can be used on a field. When a field Declaration includes a readonly modifier, the value assignment introduced by this Declaration can only appear as part of the Declaration, or in constructors of the same type.

Extern

The extern modifier is used to declare an external implementation method. The common use of the extern modifier is to use it with the DllImport attribute when calling unmanaged code using the Interop service. In this case, the method must also be declared as static

Event

The event keyword is used to declare an event in the publisher class.

Const

The const keyword is used to modify the declaration of a field or a local variable. It specifies that the value of a field or local variable is a constant and cannot be modified.

Abstract

Abstract modifiers can be used with classes, methods, attributes, indexers, and events. Use the abstract modifier in the class declaration to indicate that a class can only be the base class of other classes. Members marked as abstract or included in an abstract class must be implemented through classes derived from the abstract class.

Access Modifier

Internal

Internal keywords are access modifiers for type and type members. Internal types or members are accessible only in files of the same assembly.

Private

The private keyword is a member access modifier. Private access is the minimum allowed access level. Private Members are accessible only when their classes and struct are declared.

Protected

The protected keyword is a member access modifier. A protected member can be accessed by a derived class instance in its class.

Public

The public keyword is an access modifier for type and type members. Public access is the highest allowed access level.


Abstract can be used with classes, methods, attributes, indexers, and events,
Identifies a class or method that can be extended but cannot be materialized and must be implemented.

As a conversion operator. If the conversion fails, null is returned.

Base is used to access base class members hidden by members of the same name in the derived class or structure.

Catch defines a code block. When a specific type of exception is thrown, the code in the block is executed.
See try and finally.

Checked is both an operator and a statement.
Make sure that the compiler checks for integer overflow during operation or conversion.

Const identifies a variable value that can be calculated during compilation, that is, a value that cannot be modified once assigned.

Delegate specifies a declaration as a delegate type. The delegate encapsulates the method as a callable object,
Can be called in the delegate object.

Enum indicates the value type of a named constant cluster.

An event allows a class or object to provide notification members. It must be a delegate type.

Explicit is an operator that defines user-defined conversion operators,
It is usually used to convert a built-in type to a user-defined type or a reverse operation.
The display conversion operator is called when conversion is required.

Extern identifies a method that will be implemented in the external part (usually not the c # language.


Finally defines a code block and runs it after the program control leaves the try code. See try and catch.


Fixed assigns a pointer to a variable at a fixed memory position when executing a code block.


Foreach is used to traverse the elements of a cluster.


Goto: A jump statement that redirects program execution to a tag statement.

Implicit is an operator that defines a user-defined conversion operator.
It is usually used to convert a predefined type to a user-defined type or a reverse operation.
Implicit conversion operators must be used for conversion.

Interface specifies a declaration as the interface type, that is, the implementation class or the contract that must be followed by the construction.

Internal is an access modifier.

Namespace defines the type and namespace of a logical group.

Operator is used to declare or load an operator.

An out parameter identifies a parameter that will be affected,
This parameter does not need to be initialized first.

Params declares an array of parameters. If this parameter is used, you must modify the last parameter.
Optional parameters are allowed.

The value of readonly that identifies a variable cannot be modified after initialization.

Ref identifies a parameter value that may be affected.

Sealed prevents types from being derived and methods and properties from being overwritten.

A sizeof operator returns the length of a value type in bytes.

Stackalloc returns the pointer of a memory block allocated on the stack.

Struct is a value type that can declare constants, fields, methods, property,
Indexer, operator, constructor, and embedded type.

Throw an exception.

A part of the try exception handling code block. Try code block may include
Code that throws an exception. See catch and finally keywords.

Typeof is an operator that returns the type of the input parameter.

Unchecked prohibits overflow check.

Unsafe indicates the code block, method, or class that contains pointer operations.

When using is used for a namespace, the using keyword allows access to types in the namespace,
You do not need to specify its full name. It is also used to define the scope of the finalization operation.
Virtual: A method modifier that identifies a method that can be overwritten.

Volatile identifies an attribute that can be modified by the operating system, some hardware devices, or concurrent threads.



A General constructor is always of the public type. If it is of the private type, it indicates that the class cannot be instantiated, which is usually used for classes that only contain static members.

To declare an overload of a virtual method in a derived class, you must add the override keyword to the declaration and do not have new, static, or virtual modifiers.

The sealed modifier is used in the Declaration to prevent the class from being inherited by other classes.
C # keywords


Many back-end students are confused about the C # keywords. Now, I want to learn the meanings of these keywords in group Q 162542073 of 51RGB.

Type

Void

When used as the return type of a method, the void keyword specifies that the method does not return a value.

Void is not allowed in the parameter list of the method. Declare a non-parametric, Non-Return Value Method in the following form:

Ovid SampleMethod ();

Var

Variables declared in the method range can have implicit type var. Implicit local variables are strongly typed (as if you have declared this type), but the type is determined by the compiler. Return Value


Reference Type

Class

Class is declared using the keyword class.


Delegate

The Declaration of the delegate type is similar to the method signature. There is a return value and any number of parameters of any type:
Public delegate void TestDelegate (string message );

Public delegate int TestDelegate (MyType m, long num );

Delegate is a reference type that can be used to encapsulate naming or anonymous methods. The delegate is similar to the function pointer in C ++. However, the delegate type is safe and reliable.

Interface

The interface only contains the signatures of methods, properties, events, or indexers. The member implementation is completed in the class or structure that implements the interface.

Object

The object type is the alias of the Object in. NET Framework. In the unified type system of C #, all types (pre-defined type, user-defined type, reference type and value type) are inherited directly or indirectly from the Object. Any type of value can be assigned to an object-type variable. The process of converting a value type variable to an object is called "Packing ". The process of converting an object type variable to a value type is called "unboxing ".

String

String represents a sequence composed of zero or more Unicode characters. String is the alias of String in. NET Framework.

Although string is a reference type, it defines equal operators (= and! =) Is to compare the value of a string object (rather than a reference. This makes the test of string equality more intuitive.


Modifier

Override

Override modifiers must be used to extend or modify the abstract or virtual Implementation of inherited methods, attributes, indexers, or events.

Virtual

Virtual keywords are used to modify methods, attributes, indexers, or event declarations, and enable them to be overwritten in a derived class. For example, this method can be overwritten by any class that inherits it.

Volatile

The volatile keyword indicates that a field can be modified by multiple concurrent threads. Fields declared as volatile are not restricted by Compiler Optimization (assuming that they are accessed by a single thread. This ensures that the field displays the latest value at any time.

Unsafe

The unsafe keyword indicates the insecure context, which is required for any operations involving pointers.

Static

Use the static modifier to declare a static member of a type rather than a specific object. Static modifiers can be used for classes, fields, methods, attributes, operators, events, and constructors, but cannot be used for types other than the indexer, destructor, or class.

Sealed

When the sealed modifier is applied to a class, this modifier prevents other classes from inheriting from the class. In the following example, Class B inherits from Class A, but no class can inherit from Class B.

Readonly

The readonly keyword is a modifier that can be used on a field. When a field Declaration includes a readonly modifier, the value assignment introduced by this Declaration can only appear as part of the Declaration, or in constructors of the same type.

Extern

The extern modifier is used to declare an external implementation method. The common use of the extern modifier is to use it with the DllImport attribute when calling unmanaged code using the Interop service. In this case, the method must also be declared as static

Event

The event keyword is used to declare an event in the publisher class.

Const

The const keyword is used to modify the declaration of a field or a local variable. It specifies that the value of a field or local variable is a constant and cannot be modified.

Abstract

Abstract modifiers can be used with classes, methods, attributes, indexers, and events. Use the abstract modifier in the class declaration to indicate that a class can only be the base class of other classes. Members marked as abstract or included in an abstract class must be implemented through classes derived from the abstract class.
Www.51rgb.com
Access Modifier

Internal

Internal keywords are access modifiers for type and type members. Internal types or members are accessible only in files of the same assembly.

Private

The private keyword is a member access modifier. Private access is the minimum allowed access level. Private Members are accessible only when their classes and struct are declared.

Protected

The protected keyword is a member access modifier. A protected member can be accessed by a derived class instance in its class.

Public

The public keyword is an access modifier for type and type members. Public access is the highest allowed access level.


Abstract can be used with classes, methods, attributes, indexers, and events,
Identifies a class or method that can be extended but cannot be materialized and must be implemented.

As a conversion operator. If the conversion fails, null is returned.

Base is used to access base class members hidden by members of the same name in the derived class or structure.

Catch defines a code block. When a specific type of exception is thrown, the code in the block is executed.
See try and finally.

Checked is both an operator and a statement.
Make sure that the compiler checks for integer overflow during operation or conversion.

Const identifies a variable value that can be calculated during compilation, that is, a value that cannot be modified once assigned.

Delegate specifies a declaration as a delegate type. The delegate encapsulates the method as a callable object,
Can be called in the delegate object.

Enum indicates the value type of a named constant cluster.

An event allows a class or object to provide notification members. It must be a delegate type.

Explicit is an operator that defines user-defined conversion operators,
It is usually used to convert a built-in type to a user-defined type or a reverse operation.
The display conversion operator is called when conversion is required.

Extern identifies a method that will be implemented in the external part (usually not the c # language.


Finally defines a code block and runs it after the program control leaves the try code. See try and catch.


Fixed assigns a pointer to a variable at a fixed memory position when executing a code block.


Foreach is used to traverse the elements of a cluster.


Goto: A jump statement that redirects program execution to a tag statement.

Implicit is an operator that defines a user-defined conversion operator.
It is usually used to convert a predefined type to a user-defined type or a reverse operation.
Implicit conversion operators must be used for conversion.

Interface specifies a declaration as the interface type, that is, the implementation class or the contract that must be followed by the construction.

Internal is an access modifier.

Namespace defines the type and namespace of a logical group.

Operator is used to declare or load an operator.

An out parameter identifies a parameter that will be affected,
This parameter does not need to be initialized first.

Params declares an array of parameters. If this parameter is used, you must modify the last parameter.
Optional parameters are allowed.

The value of readonly that identifies a variable cannot be modified after initialization.

Ref identifies a parameter value that may be affected.

Sealed prevents types from being derived and methods and properties from being overwritten.

A sizeof operator returns the length of a value type in bytes.

Stackalloc returns the pointer of a memory block allocated on the stack.

Struct is a value type that can declare constants, fields, methods, property,
Indexer, operator, constructor, and embedded type.

Throw an exception.

A part of the try exception handling code block. Try code block may include
Code that throws an exception. See catch and finally keywords.

Typeof is an operator that returns the type of the input parameter.

Unchecked prohibits overflow check.

Unsafe indicates the code block, method, or class that contains pointer operations.

When using is used for a namespace, the using keyword allows access to types in the namespace,
You do not need to specify its full name. It is also used to define the scope of the finalization operation.
Virtual: A method modifier that identifies a method that can be overwritten.

Volatile identifies an attribute that can be modified by the operating system, some hardware devices, or concurrent threads.



A General constructor is always of the public type. If it is of the private type, it indicates that the class cannot be instantiated, which is usually used for classes that only contain static members.

To declare an overload of a virtual method in a derived class, you must add the override keyword to the declaration and do not have new, static, or virtual modifiers.

The sealed modifier is used in the Declaration to prevent the class from being inherited by other classes.
C # keywords


Many back-end students are confused about the C # keywords. Now, I want to learn the meanings of these keywords in group Q 162542073 of 51RGB.

Type

Void

When used as the return type of a method, the void keyword specifies that the method does not return a value.

Void is not allowed in the parameter list of the method. Declare a non-parametric, Non-Return Value Method in the following form:

Ovid SampleMethod ();

Var

Variables declared in the method range can have implicit type var. Implicit local variables are strongly typed (as if you have declared this type), but the type is determined by the compiler. Return Value


Reference Type

Class

Class is declared using the keyword class.


Delegate

The Declaration of the delegate type is similar to the method signature. There is a return value and any number of parameters of any type:
Public delegate void TestDelegate (string message );

Public delegate int TestDelegate (MyType m, long num );

Delegate is a reference type that can be used to encapsulate naming or anonymous methods. The delegate is similar to the function pointer in C ++. However, the delegate type is safe and reliable.
Www.51rgb.com
Interface

The interface only contains the signatures of methods, properties, events, or indexers. The member implementation is completed in the class or structure that implements the interface.

Object

The object type is the alias of the Object in. NET Framework. In the unified type system of C #, all types (pre-defined type, user-defined type, reference type and value type) are inherited directly or indirectly from the Object. Any type of value can be assigned to an object-type variable. The process of converting a value type variable to an object is called "Packing ". The process of converting an object type variable to a value type is called "unboxing ".

String

String represents a sequence composed of zero or more Unicode characters. String is the alias of String in. NET Framework.

Although string is a reference type, it defines equal operators (= and! =) Is to compare the value of a string object (rather than a reference. This makes the test of string equality more intuitive.


Modifier

Override

Override modifiers must be used to extend or modify the abstract or virtual Implementation of inherited methods, attributes, indexers, or events.

Virtual

Virtual keywords are used to modify methods, attributes, indexers, or event declarations, and enable them to be overwritten in a derived class. For example, this method can be overwritten by any class that inherits it.

Volatile

The volatile keyword indicates that a field can be modified by multiple concurrent threads. Fields declared as volatile are not restricted by Compiler Optimization (assuming that they are accessed by a single thread. This ensures that the field displays the latest value at any time.

Unsafe

The unsafe keyword indicates the insecure context, which is required for any operations involving pointers.

Static

Use the static modifier to declare a static member of a type rather than a specific object. Static modifiers can be used for classes, fields, methods, attributes, operators, events, and constructors, but cannot be used for types other than the indexer, destructor, or class.

Sealed

When the sealed modifier is applied to a class, this modifier prevents other classes from inheriting from the class. In the following example, Class B inherits from Class A, but no class can inherit from Class B.

Readonly

The readonly keyword is a modifier that can be used on a field. When a field Declaration includes a readonly modifier, the value assignment introduced by this Declaration can only appear as part of the Declaration, or in constructors of the same type.

Extern

The extern modifier is used to declare an external implementation method. The common use of the extern modifier is to use it with the DllImport attribute when calling unmanaged code using the Interop service. In this case, the method must also be declared as static

Event

The event keyword is used to declare an event in the publisher class.

Const

The const keyword is used to modify the declaration of a field or a local variable. It specifies that the value of a field or local variable is a constant and cannot be modified.

Abstract

Abstract modifiers can be used with classes, methods, attributes, indexers, and events. Use the abstract modifier in the class declaration to indicate that a class can only be the base class of other classes. Members marked as abstract or included in an abstract class must be implemented through classes derived from the abstract class.
Www.51rgb.com
Access Modifier

Internal

Internal keywords are access modifiers for type and type members. Internal types or members are accessible only in files of the same assembly.

Private

The private keyword is a member access modifier. Private access is the minimum allowed access level. Private Members are accessible only when their classes and struct are declared.

Protected

The protected keyword is a member access modifier. A protected member can be accessed by a derived class instance in its class.

Public

The public keyword is an access modifier for type and type members. Public access is the highest allowed access level.


Abstract can be used with classes, methods, attributes, indexers, and events,
Identifies a class or method that can be extended but cannot be materialized and must be implemented.

As a conversion operator. If the conversion fails, null is returned.

Base is used to access base class members hidden by members of the same name in the derived class or structure.

Catch defines a code block. When a specific type of exception is thrown, the code in the block is executed.
See try and finally.

Checked is both an operator and a statement.
Make sure that the compiler checks for integer overflow during operation or conversion.

Const identifies a variable value that can be calculated during compilation, that is, a value that cannot be modified once assigned.

Delegate specifies a declaration as a delegate type. The delegate encapsulates the method as a callable object,
Can be called in the delegate object.

Enum indicates the value type of a named constant cluster.

An event allows a class or object to provide notification members. It must be a delegate type.

Explicit is an operator that defines user-defined conversion operators,
It is usually used to convert a built-in type to a user-defined type or a reverse operation.
The display conversion operator is called when conversion is required.

Extern identifies a method that will be implemented in the external part (usually not the c # language.


Finally defines a code block and runs it after the program control leaves the try code. See try and catch.


Fixed assigns a pointer to a variable at a fixed memory position when executing a code block.


Foreach is used to traverse the elements of a cluster.


Goto: A jump statement that redirects program execution to a tag statement.

Implicit is an operator that defines a user-defined conversion operator.
It is usually used to convert a predefined type to a user-defined type or a reverse operation.
Implicit conversion operators must be used for conversion.

Interface specifies a declaration as the interface type, that is, the implementation class or the contract that must be followed by the construction.

Internal is an access modifier.

Namespace defines the type and namespace of a logical group.

Operator is used to declare or load an operator.

An out parameter identifies a parameter that will be affected,
This parameter does not need to be initialized first.

Params declares an array of parameters. If this parameter is used, you must modify the last parameter.
Optional parameters are allowed.

The value of readonly that identifies a variable cannot be modified after initialization.

Ref identifies a parameter value that may be affected.

Sealed prevents types from being derived and methods and properties from being overwritten.

A sizeof operator returns the length of a value type in bytes.

Stackalloc returns the pointer of a memory block allocated on the stack.

Struct is a value type that can declare constants, fields, methods, property,
Indexer, operator, constructor, and embedded type.

Throw an exception.

A part of the try exception handling code block. Try code block may include
Code that throws an exception. See catch and finally keywords.

Typeof is an operator that returns the type of the input parameter.

Unchecked prohibits overflow check.

Unsafe indicates the code block, method, or class that contains pointer operations.

When using is used for a namespace, the using keyword allows access to types in the namespace,
You do not need to specify its full name. It is also used to define the scope of the finalization operation.
Virtual: A method modifier that identifies a method that can be overwritten.

Volatile identifies an attribute that can be modified by the operating system, some hardware devices, or concurrent threads.



A General constructor is always of the public type. If it is of the private type, it indicates that the class cannot be instantiated, which is usually used for classes that only contain static members.

To declare an overload of a virtual method in a derived class, you must add the override keyword to the declaration and do not have new, static, or virtual modifiers.

The sealed modifier is used in the Declaration to prevent the class from being inherited by other classes.
For more video tutorials, please go to 51rgb official website http://www.51rgb.com

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.