C # keyword Summary

Source: Internet
Author: User

C # keywords:

Abstract

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

As

A Conversion operator returns NULL if the conversion fails.

Base

Used to access base class members hidden by members of the same name in a 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

It 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 and can be called in the delegate object.

Enum

Indicates the value type of a named constant cluster.

Event

A member that allows a class or object to provide notifications. It must be a delegate type.

 

Explicit

A user-defined conversion operator 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 in the C # language.

Finally

Define a code block and execute it quickly after the program control leaves the try code. See try and catch.

 

Fixed

When a code block is executed, a pointer is assigned to a variable at a fixed memory position.

 

Foreach

Used to traverse the elements of a cluster.

Goto

A jump statement redirects program execution to a tag statement.

Implicit

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

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

Internal

An access modifier.

Namespace

Defines the type and namespace of a logical group.

Operator

Used to declare or load an operator.

Out

Identifies a parameter that will be affected by a parameter value, but this parameter does not need to be initialized when you pass in the method.

Params

Declare a parameter array. If this parameter is used, you must modify the last parameter. Optional parameters are allowed.

Readonly

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

Ref

Identifies a parameter value that may be affected.

Sealed

Prevent the type from being derived, and prevent methods and properties from being overwritten.

Sizeof

An operator returns the length of a value type in bytes.

Stackalloc

Returns the pointer of a memory block allocated on the heap.

Struct

Struct is a value type that can declare constants, fields, methods, properties, indexers, operators, constructors, and embedded types.

Throw

Throw an exception.

Try

One of the components of the exception handling code block. The try code block contains code that may throw exceptions. See catch and finally keywords.

Typeof

Returns the input parameter type.

Unchecked

Overflow check is prohibited.

Unsafe

Mark a code block, method, or class that contains pointer operations.

Using

When used for a namespace, the using keyword allows access to the type in the namespace without specifying 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.

 

The sealed modifier indicates that when the modifier is sealed for the class, it indicates that the class cannot be inherited and cannot be used together with the abstract, because the two modifiers are mutually exclusive for the method and attribute in terms of meaning, indicates that the method or attribute cannot be inherited and must be used with the override keyword, because the method or attribute using the sealed modifier must be the Virtual Member of the base class, which is usually used to implement third-party class libraries without being inherited by the client, or used for classes that do not need to be inherited to prevent misuse of inheritance, resulting in disorder of the hierarchy, and proper use of sealed
Modifier can also improve the running efficiency, because you do not need to consider inheritance

Abstract & Virtual

Abstract modifiers can be used with classes, methods, attributes, indexers, and events.

Use the abstract modifier in the class declaration to indicate that the class can only be the base class of other classes. The following describes some abstract features: they cannot be instantiated; they can contain abstract methods and abstract accessors; they cannot be modified using the sealed modifier, meaning that the class cannot be inherited; A non-abstract class derived from an abstract class must include all the inherited abstract methods and the implementation of the abstract accessors;

Use the abstract modifier in a method or attribute declaration to indicate that the method or attribute does not contain an implementation. "Abstract" can modify classes, methods, attributes, indexers, and events.

When you see the virtual keyword, there is a question: "virtual" keywords can only modify methods and attributes, but cannot modify classes ~ But I clearly remember that when the teacher talked about C ++, there was a concept called the virtual base class. Does C # Remove this virtual feature? Then I went to Google to find the answer ~ I saw two articles: "C ++ virtual base class" and "in-depth analysis of the C # Inheritance Mechanism", and finally realized that the inheritance mechanism of the two was different. C ++ allows multi-inheritance, while C # only allows the derived class to inherit from one class. The ambiguity arising from multi-Inheritance needs to be solved by the virtual base class, therefore, C ++ has the concept of a virtual base class, while C # does not have the ambiguity arising from inheritance due to single inheritance,

Therefore, virtual key modifiers are not required.




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.