logo search
CSharp_Prog_Guide

Общие сведения о классах

Классы имеют следующие свойства:

Structs

Structs are defined by using the struct keyword, for example:

public struct PostalAddress

{

// Fields, properties, methods and events go here...

}

Structs share most of the same syntax as classes, although structs are more limited than classes:

Because copies of structs are created and destroyed automatically by the compiler, a default constructor and destructor are unnecessary. In effect, the compiler implements the default constructor by assigning all the fields of their default values. Structs cannot inherit from classes or other structs.

Structs are value types. When an object is created from a struct and assigned to a variable, the variable contains the complete value of the struct. When a variable that contains a struct is copied, all the data is copied, and any modification to the new copy does not change the data for the old copy. Because structs do not use references, they do not have identity; you cannot distinguish between two instances of a value type with the same data. All value types in C# derive from ValueType, which inherits from Object.

Value types can be converted to reference types by the compiler in a process known as boxing.

Structs Overview

Structs have the following properties: