X hits on this document





209 / 396

Chapter ‎18   Unsafe code

10. Classes

A class is a data structure that may contain data members (constants and fields), function members (methods, properties, events, indexers, operators, instance constructors, destructors and static constructors), and nested types. Class types support inheritance, a mechanism whereby a derived class can extend and specialize a base class.

10.1 Class declarations

A class-declaration is a type-declaration (§‎9.5) that declares a new class.

class-declaration: attributesopt   class-modifiersopt   class   identifier   class-baseopt   class-body   ;opt

A class-declaration consists of an optional set of attributes (§‎17), followed by an optional set of class-modifiers (§‎10.1.1), followed by the keyword class and an identifier that names the class, followed by an optional class-base specification (§‎10.1.2), followed by a class-body (§‎10.1.3), optionally followed by a semicolon.

10.1.1 Class modifiers

A class-declaration may optionally include a sequence of class modifiers:

class-modifiers: class-modifier class-modifiers   class-modifier

class-modifier: new public protected internal private abstract sealed

It is a compile-time error for the same modifier to appear multiple times in a class declaration.

The new modifier is permitted on nested classes. It specifies that the class hides an inherited member by the same name, as described in §‎10.2.2. It is a compile-time error for the new modifier to appear on a class declaration that is not a nested class declaration.

The public, protected, internal, and private modifiers control the accessibility of the class. Depending on the context in which the class declaration occurs, some of these modifiers may not be permitted (§‎3.5.1).

The abstract and sealed modifiers are discussed in the following sections. Abstract classes

The abstract modifier is used to indicate that a class is incomplete and that it is intended to be used only as a base class. An abstract class differs from a non-abstract class in the following ways:

An abstract class cannot be instantiated directly, and it is a compile-time error to use the new operator on an abstract class. While it is possible to have variables and values whose compile-time types are abstract, such variables and values will necessarily either be null or contain references to instances of non-abstract classes

Copyright Microsoft Corporation 1999-2003. All Rights Reserved.196

Document info
Document views685
Page views685
Page last viewedThu Oct 27 18:57:20 UTC 2016