Type Definitions
You define new types from existing types. Built-in value types, pointers, arrays, and delegates are defined when they are used and are referred to as implicit types. Types can be nested; that is, a type can be a member of another type.
Note
For the specific syntax needed to define .NET Framework types, as well as examples that illustrate the elements of a type definition, see the reference documentation for specific .NET Framework languages.
A type definition includes:
Any attributes defined on the type.
The type's visibility.
The type's name.
The type's base type.
Any interfaces implemented by the type.
Definitions for each of the type's members.
Attributes
Attributes provide additional user-defined metadata. Attributes can be applied to almost any language element — types, properties, methods, and so on.
Type Accessibility
All types have an accessibility modifier that governs their accessibility from other types. The following table describes the type accessibilities supported by the runtime.
Accessibility |
Description |
---|---|
public |
The type is accessible by all assemblies. |
assembly |
The type is accessible only from within the assembly. |
The accessibility of a nested type depends on its accessibility domain, which is determined by both the declared accessibility of the member and the accessibility domain of the immediately containing type. However, the accessibility domain of a nested type cannot exceed that of the containing type.
The accessibility domain of a nested member M declared in a type T within a program P is defined as follows (noting that M might itself be a type):
If the declared accessibility of M is public, the accessibility domain of M is the accessibility domain of T.
If the declared accessibility of M is protected internal, the accessibility domain of M is the intersection of the accessibility domain of T with the program text of P and the program text of any type derived from T declared outside P.
If the declared accessibility of M is protected, the accessibility domain of M is the intersection of the accessibility domain of T with the program text of T and any type derived from T.
If the declared accessibility of M is internal, the accessibility domain of M is the intersection of the accessibility domain of T with the program text of P.
If the declared accessibility of M is private, the accessibility domain of M is the program text of T.
Type Names
The common type system imposes only two restrictions on names:
All names are encoded as strings of Unicode (16-bit) characters.
Names are not permitted to have an embedded (16-bit) value of 0x0000.
All comparisons are done on a byte-by-byte basis, and are thus case-sensitive and locale-independent.
Although a type might reference types from other modules and assemblies, a type is fully defined within one module. Type names need only be unique within an assembly. To fully identify a type, the type name must be qualified by the assembly that contains the implementation of the type. For more information, see Specifying Fully Qualified Type Names.
Base Types and Interfaces
A type can inherit values and behaviors from another type. The common type system does not allow types to inherit from more than one base type.
A type can implement any number of interfaces. To implement an interface, a type must implement all the virtual members of that interface. A virtual method can be implemented by a derived type and can be invoked either statically or dynamically. For more information about virtual members, see Type Members. For more information about inheritance and interfaces, see Classes and Interfaces.
Type Members
The behavior and state of a type are defined by the members of the type: events, fields, nested types, methods, and properties. For more information, see Type Members.