Jo Shields a575963da9 Imported Upstream version 3.6.0
Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
2014-08-13 10:39:27 +01:00

8 lines
2.7 KiB
XML

<?xml version="1.0"?>
<clause number="11.1" title="Value types">
<paragraph>A value type is either a struct type or an enumeration type. C# provides a set of predefined struct types called the simple types. The simple types are identified through reserved words. <grammar_production><name><non_terminal where="11.1">value-type</non_terminal></name> : <rhs><non_terminal where="11.1">struct-type</non_terminal></rhs><rhs><non_terminal where="11.1">enum-type</non_terminal></rhs></grammar_production><grammar_production><name><non_terminal where="11.1">struct-type</non_terminal></name> : <rhs><non_terminal where="10.8">type-name</non_terminal></rhs><rhs><non_terminal where="11.1">simple-type</non_terminal></rhs></grammar_production><grammar_production><name><non_terminal where="11.1">simple-type</non_terminal></name> : <rhs><non_terminal where="11.1">numeric-type</non_terminal></rhs><rhs><keyword>bool</keyword></rhs></grammar_production><grammar_production><name><non_terminal where="11.1">numeric-type</non_terminal></name> : <rhs><non_terminal where="11.1">integral-type</non_terminal></rhs><rhs><non_terminal where="11.1">floating-point-type</non_terminal></rhs><rhs><keyword>decimal</keyword></rhs></grammar_production><grammar_production><name><non_terminal where="11.1">integral-type</non_terminal></name> : <rhs><keyword>sbyte</keyword></rhs><rhs><keyword>byte</keyword></rhs><rhs><keyword>short</keyword></rhs><rhs><keyword>ushort</keyword></rhs><rhs><keyword>int</keyword></rhs><rhs><keyword>uint</keyword></rhs><rhs><keyword>long</keyword></rhs><rhs><keyword>ulong</keyword></rhs><rhs><keyword>char</keyword></rhs></grammar_production><grammar_production><name><non_terminal where="11.1">floating-point-type</non_terminal></name> : <rhs><keyword>float</keyword></rhs><rhs><keyword>double</keyword></rhs></grammar_production><grammar_production><name><non_terminal where="11.1">enum-type</non_terminal></name> : <rhs><non_terminal where="10.8">type-name</non_terminal></rhs></grammar_production></paragraph>
<paragraph>All value types implicitly inherit from class object. It is not possible for any type to derive from a value type, and value types are thus implicitly sealed (<hyperlink>17.1.1.2</hyperlink>). </paragraph>
<paragraph>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. </paragraph>
<paragraph>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. </paragraph>
</clause>