[jit] Fix the saving of the 'cfg->ret_var_set' flag when inlining, it was set to...
[mono.git] / mcs / docs / ecma334 / 21.3.xml
1 <?xml version="1.0"?>
2 <clause number="21.3" title="Enum members">
3   <paragraph>The body of an enum type declaration defines zero or more enum members, which are the named constants of the enum type. No two enum members can have the same name. <grammar_production><name><non_terminal where="21.3">enum-member-declaration</non_terminal>s</name> : <rhs><non_terminal where="21.3">enum-member-declaration</non_terminal></rhs><rhs><non_terminal where="21.3">enum-member-declarations</non_terminal><terminal>,</terminal><non_terminal where="21.3">enum-member-declaration</non_terminal></rhs></grammar_production><grammar_production><name><non_terminal where="21.3">enum-member-declaration</non_terminal></name> : <rhs><non_terminal where="24.2">attributes</non_terminal><opt/><non_terminal where="9.4.2">identifier</non_terminal></rhs><rhs><non_terminal where="24.2">attributes</non_terminal><opt/><non_terminal where="9.4.2">identifier</non_terminal><terminal>=</terminal><non_terminal where="14.15">constant-expression</non_terminal></rhs></grammar_production></paragraph>
4   <paragraph>Each enum member has an associated constant value. The type of this value is the underlying type for the containing enum. The constant value for each enum member must be in the range of the underlying type for the enum. <example>[Example: The example <code_example><![CDATA[
5 enum Color: uint  
6 {  
7    Red = -1,  
8    Green = -2,  
9    Blue = -3  
10 }  
11 ]]></code_example>results in a compile-time error because the constant values -1, -2, and -3 are not in the range of the underlying integral type <keyword>uint</keyword>. end example]</example> </paragraph>
12   <paragraph>Multiple enum members may share the same associated value. <example>[Example: The example <code_example><![CDATA[
13 enum Color   
14 {  
15    Red,  
16    Green,  
17    Blue,  
18    
19    Max = Blue  
20 }  
21 ]]></code_example>shows an enum that has two enum members-Blue and Max-that have the same associated value. end example]</example> </paragraph>
22   <paragraph>The associated value of an enum member is assigned either implicitly or explicitly. If the declaration of the enum member has a <non_terminal where="14.15">constant-expression</non_terminal> initializer, the value of that constant expression, implicitly converted to the underlying type of the enum, is the associated value of the enum member. If the declaration of the enum member has no initializer, its associated value is set implicitly, as follows: <list><list_item> If the enum member is the first enum member declared in the enum type, its associated value is zero. </list_item><list_item> Otherwise, the associated value of the enum member is obtained by increasing the associated value of the textually preceding enum member by one. This increased value must be within the range of values that can be represented by the underlying type. </list_item></list></paragraph>
23   <paragraph>
24     <example>[Example: The example <code_example><![CDATA[
25 using System;  
26 enum Color  
27 {  
28    Red,  
29    Green = 10,  
30    Blue  
31 }  
32 class Test  
33 {  
34    static void Main() {  
35       Console.WriteLine(StringFromColor(Color.Red));  
36       Console.WriteLine(StringFromColor(Color.Green));  
37       Console.WriteLine(StringFromColor(Color.Blue));  
38    }  
39    static string StringFromColor(Color c) {  
40       switch (c) {  
41          case Color.Red:   
42          return String.Format("Red = {0}", (int) c);  
43          case Color.Green:  
44          return String.Format("Green = {0}", (int) c);  
45          case Color.Blue:  
46          return String.Format("Blue = {0}", (int) c);  
47          default:  
48          return "Invalid color";  
49       }  
50    }  
51 }  
52 ]]></code_example>prints out the enum member names and their associated values. The output is: <code_example><![CDATA[
53 Red = 0  
54 Green = 10  
55 Blue = 11  
56 ]]></code_example>for the following reasons: <list><list_item> the enum member Red is automatically assigned the value zero (since it has no initializer and is the first enum member); </list_item><list_item> the enum member Green is explicitly given the value 10; </list_item><list_item> and the enum member Blue is automatically assigned the value one greater than the member that textually precedes it. end example]</list_item></list></example>
57   </paragraph>
58   <paragraph>The associated value of an enum member may not, directly or indirectly, use the value of its own associated enum member. Other than this circularity restriction, enum member initializers may freely refer to other enum member initializers, regardless of their textual position. Within an enum member initializer, values of other enum members are always treated as having the type of their underlying type, so that casts are not necessary when referring to other enum members. </paragraph>
59   <paragraph>
60     <example>[Example: The example <code_example><![CDATA[
61 enum Circular  
62 {  
63    A = B,  
64    B  
65 }  
66 ]]></code_example>results in a compile-time error because the declarations of A and B are circular. A depends on B explicitly, and B depends on A implicitly. end example]</example>
67   </paragraph>
68   <paragraph>Enum members are named and scoped in a manner exactly analogous to fields within classes. The scope of an enum member is the body of its containing enum type. Within that scope, enum members can be referred to by their simple name. From all other code, the name of an enum member must be qualified with the name of its enum type. Enum members do not have any declared accessibility-an enum member is accessible if its containing enum type is accessible. </paragraph>
69 </clause>