X hits on this document





274 / 396

Chapter ‎18   Unsafe code

struct-interfaces: :   interface-type-list

Interface implementations are discussed further in §‎13.4.

11.1.3 Struct body

The struct-body of a struct defines the members of the struct.

struct-body: {   struct-member-declarationsopt   }

11.2 Struct members

The members of a struct consist of the members introduced by its struct-member-declarations and the members inherited from the type System.ValueType.

struct-member-declarations: struct-member-declaration struct-member-declarations   struct-member-declaration

struct-member-declaration: constant-declaration field-declaration method-declaration property-declaration event-declaration indexer-declaration operator-declaration constructor-declaration static-constructor-declaration type-declaration

Except for the differences noted in §‎11.3, the descriptions of class members provided in §‎10.2 through §‎10.11 apply to struct members as well.

11.3 Class and struct differences

Structs differ from classes in several important ways:

Structs are value types (§‎11.3.1).

All struct types implicitly inherit from the class System.ValueType (§‎11.3.2).

Assignment to a variable of a struct type creates a copy of the value being assigned (§‎11.3.3).

The default value of a struct is the value produced by setting all value type fields to their default value and all reference type fields to null (§‎11.3.4).

Boxing and unboxing operations are used to convert between a struct type and object (§‎11.3.5).

The meaning of this is different for structs (§‎11.3.6).

Instance field declarations for a struct are not permitted to include variable initializers (§‎11.3.7).

A struct is not permitted to declare a parameterless instance constructor (§‎11.3.8).

A struct is not permitted to declare a destructor (§‎11.3.9).

11.3.1 Value semantics

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

Document info
Document views575
Page views575
Page last viewedTue Oct 25 13:49:39 UTC 2016