X hits on this document





87 / 396


integral-type: sbyte byte short ushort int uint long ulong char

floating-point-type: float double

enum-type: type-name

A variable of a value type always contains a value of that type. Unlike reference types, it is not possible for a value of a value type to be null, or to reference an object of a more derived type.

Assignment to a variable of a value type creates a copy of the value being assigned. This differs from assignment to a variable of a reference type, which copies the reference but not the object identified by the reference.

4.1.1 The System.ValueType type

All value types implicitly inherit from the class System.ValueType, which, in turn, inherits from class object. It is not possible for any type to derive from a value type, and value types are thus implicitly sealed (§‎

Note that System.ValueType is not itself a value-type. Rather, it is a class-type from which all value-types are automatically derived.

4.1.2 Default constructors

All value types implicitly declare a public parameterless instance constructor called the default constructor. The default constructor returns a zero-initialized instance known as the default value for the value type:

For all simple-types, the default value is the value produced by a bit pattern of all zeros:

For sbyte, byte, short, ushort, int, uint, long, and ulong, the default value is 0.

For char, the default value is '\x0000'.

For float, the default value is 0.0f.

For double, the default value is 0.0d.

For decimal, the default value is 0.0m.

For bool, the default value is false.

For an enum-type E, the default value is 0.

For a struct-type, the default value is the value produced by setting all value type fields to their default value and all reference type fields to null.

Like any other instance constructor, the default constructor of a value type is invoked using the new operator. For efficiency reasons, this requirement is not intended to actually have the implementation generate a constructor call. In the example below, variables i and j are both initialized to zero.

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

Document info
Document views1277
Page views1277
Page last viewedFri Jan 20 14:55:39 UTC 2017