
- •Foreword
- •Introduction
- •Scope
- •Conformance
- •Normative references
- •Definitions
- •Notational conventions
- •Acronyms and abbreviations
- •General description
- •Language overview
- •Getting started
- •Types
- •Predefined types
- •Conversions
- •Array types
- •Type system unification
- •Variables and parameters
- •Automatic memory management
- •Expressions
- •Statements
- •Classes
- •Constants
- •Fields
- •Methods
- •Properties
- •Events
- •Operators
- •Indexers
- •Instance constructors
- •Destructors
- •Static constructors
- •Inheritance
- •Static classes
- •Partial type declarations
- •Structs
- •Interfaces
- •Delegates
- •Enums
- •Namespaces and assemblies
- •Versioning
- •Extern Aliases
- •Attributes
- •Generics
- •Why generics?
- •Creating and consuming generics
- •Multiple type parameters
- •Constraints
- •Generic methods
- •Anonymous methods
- •Iterators
- •Lexical structure
- •Programs
- •Grammars
- •Lexical grammar
- •Syntactic grammar
- •Grammar ambiguities
- •Lexical analysis
- •Line terminators
- •Comments
- •White space
- •Tokens
- •Unicode escape sequences
- •Identifiers
- •Keywords
- •Literals
- •Boolean literals
- •Integer literals
- •Real literals
- •Character literals
- •String literals
- •The null literal
- •Operators and punctuators
- •Pre-processing directives
- •Conditional compilation symbols
- •Pre-processing expressions
- •Declaration directives
- •Conditional compilation directives
- •Diagnostic directives
- •Region control
- •Line directives
- •Pragma directives
- •Basic concepts
- •Application startup
- •Application termination
- •Declarations
- •Members
- •Namespace members
- •Struct members
- •Enumeration members
- •Class members
- •Interface members
- •Array members
- •Delegate members
- •Member access
- •Declared accessibility
- •Accessibility domains
- •Protected access for instance members
- •Accessibility constraints
- •Signatures and overloading
- •Scopes
- •Name hiding
- •Hiding through nesting
- •Hiding through inheritance
- •Namespace and type names
- •Unqualified name
- •Fully qualified names
- •Automatic memory management
- •Execution order
- •Types
- •Value types
- •The System.ValueType type
- •Default constructors
- •Struct types
- •Simple types
- •Integral types
- •Floating point types
- •The decimal type
- •The bool type
- •Enumeration types
- •Reference types
- •Class types
- •The object type
- •The string type
- •Interface types
- •Array types
- •Delegate types
- •Boxing and unboxing
- •Boxing conversions
- •Unboxing conversions
- •Variables
- •Variable categories
- •Static variables
- •Instance variables
- •Instance variables in classes
- •Instance variables in structs
- •Array elements
- •Value parameters
- •Reference parameters
- •Output parameters
- •Local variables
- •Default values
- •Definite assignment
- •Initially assigned variables
- •Initially unassigned variables
- •Precise rules for determining definite assignment
- •General rules for statements
- •Block statements, checked, and unchecked statements
- •Expression statements
- •Declaration statements
- •If statements
- •Switch statements
- •While statements
- •Do statements
- •For statements
- •Break, continue, and goto statements
- •Throw statements
- •Return statements
- •Try-catch statements
- •Try-finally statements
- •Try-catch-finally statements
- •Foreach statements
- •Using statements
- •Lock statements
- •General rules for simple expressions
- •General rules for expressions with embedded expressions
- •Invocation expressions and object creation expressions
- •Simple assignment expressions
- •&& expressions
- •|| expressions
- •! expressions
- •?: expressions
- •Anonymous method expressions
- •Yield statements
- •Variable references
- •Atomicity of variable references
- •Conversions
- •Implicit conversions
- •Identity conversion
- •Implicit numeric conversions
- •Implicit enumeration conversions
- •Implicit reference conversions
- •Boxing conversions
- •Implicit type parameter conversions
- •Implicit constant expression conversions
- •User-defined implicit conversions
- •Explicit conversions
- •Explicit numeric conversions
- •Explicit enumeration conversions
- •Explicit reference conversions
- •Unboxing conversions
- •User-defined explicit conversions
- •Standard conversions
- •Standard implicit conversions
- •Standard explicit conversions
- •User-defined conversions
- •Permitted user-defined conversions
- •Evaluation of user-defined conversions
- •User-defined implicit conversions
- •User-defined explicit conversions
- •Anonymous method conversions
- •Method group conversions
- •Expressions
- •Expression classifications
- •Values of expressions
- •Operators
- •Operator precedence and associativity
- •Operator overloading
- •Unary operator overload resolution
- •Binary operator overload resolution
- •Candidate user-defined operators
- •Numeric promotions
- •Unary numeric promotions
- •Binary numeric promotions
- •Member lookup
- •Base types
- •Function members
- •Argument lists
- •Overload resolution
- •Applicable function member
- •Better function member
- •Better conversion
- •Function member invocation
- •Invocations on boxed instances
- •Primary expressions
- •Literals
- •Simple names
- •Invariant meaning in blocks
- •Parenthesized expressions
- •Member access
- •Identical simple names and type names
- •Invocation expressions
- •Method invocations
- •Delegate invocations
- •Element access
- •Array access
- •Indexer access
- •This access
- •Base access
- •Postfix increment and decrement operators
- •The new operator
- •Object creation expressions
- •Array creation expressions
- •Delegate creation expressions
- •The typeof operator
- •The checked and unchecked operators
- •Default value expression
- •Anonymous methods
- •Anonymous method signatures
- •Anonymous method blocks
- •Outer variables
- •Captured outer variables
- •Instantiation of local variables
- •Anonymous method evaluation
- •Implementation example
- •Unary expressions
- •Unary plus operator
- •Unary minus operator
- •Logical negation operator
- •Bitwise complement operator
- •Prefix increment and decrement operators
- •Cast expressions
- •Arithmetic operators
- •Multiplication operator
- •Division operator
- •Remainder operator
- •Addition operator
- •Subtraction operator
- •Shift operators
- •Relational and type-testing operators
- •Integer comparison operators
- •Floating-point comparison operators
- •Decimal comparison operators
- •Boolean equality operators
- •Enumeration comparison operators
- •Reference type equality operators
- •String equality operators
- •Delegate equality operators
- •The is operator
- •The as operator
- •Logical operators
- •Integer logical operators
- •Enumeration logical operators
- •Boolean logical operators
- •Conditional logical operators
- •Boolean conditional logical operators
- •User-defined conditional logical operators
- •Conditional operator
- •Assignment operators
- •Simple assignment
- •Compound assignment
- •Event assignment
- •Expression
- •Constant expressions
- •Boolean expressions
- •Statements
- •End points and reachability
- •Blocks
- •Statement lists
- •The empty statement
- •Labeled statements
- •Declaration statements
- •Local variable declarations
- •Local constant declarations
- •Expression statements
- •Selection statements
- •The if statement
- •The switch statement
- •Iteration statements
- •The while statement
- •The do statement
- •The for statement
- •The foreach statement
- •Jump statements
- •The break statement
- •The continue statement
- •The goto statement
- •The return statement
- •The throw statement
- •The try statement
- •The checked and unchecked statements
- •The lock statement
- •The using statement
- •The yield statement
- •Namespaces
- •Compilation units
- •Namespace declarations
- •Extern alias directives
- •Using directives
- •Using alias directives
- •Using namespace directives
- •Namespace members
- •Type declarations
- •Qualified alias member
- •Classes
- •Class declarations
- •Class modifiers
- •Abstract classes
- •Sealed classes
- •Static classes
- •Class base specification
- •Base classes
- •Interface implementations
- •Class body
- •Partial declarations
- •Class members
- •Inheritance
- •The new modifier
- •Access modifiers
- •Constituent types
- •Static and instance members
- •Nested types
- •Fully qualified name
- •Declared accessibility
- •Hiding
- •this access
- •Reserved member names
- •Member names reserved for properties
- •Member names reserved for events
- •Member names reserved for indexers
- •Member names reserved for destructors
- •Constants
- •Fields
- •Static and instance fields
- •Readonly fields
- •Using static readonly fields for constants
- •Versioning of constants and static readonly fields
- •Volatile fields
- •Field initialization
- •Variable initializers
- •Static field initialization
- •Instance field initialization
- •Methods
- •Method parameters
- •Value parameters
- •Reference parameters
- •Output parameters
- •Parameter arrays
- •Static and instance methods
- •Virtual methods
- •Override methods
- •Sealed methods
- •Abstract methods
- •External methods
- •Method body
- •Method overloading
- •Properties
- •Static and instance properties
- •Accessors
- •Virtual, sealed, override, and abstract accessors
- •Events
- •Field-like events
- •Event accessors
- •Static and instance events
- •Virtual, sealed, override, and abstract accessors
- •Indexers
- •Indexer overloading
- •Operators
- •Unary operators
- •Binary operators
- •Conversion operators
- •Instance constructors
- •Constructor initializers
- •Instance variable initializers
- •Constructor execution
- •Default constructors
- •Private constructors
- •Optional instance constructor parameters
- •Static constructors
- •Destructors
- •Structs
- •Struct declarations
- •Struct modifiers
- •Struct interfaces
- •Struct body
- •Struct members
- •Class and struct differences
- •Value semantics
- •Inheritance
- •Assignment
- •Default values
- •Boxing and unboxing
- •Meaning of this
- •Field initializers
- •Constructors
- •Destructors
- •Static constructors
- •Struct examples
- •Database integer type
- •Database boolean type
- •Arrays
- •Array types
- •The System.Array type
- •Array creation
- •Array element access
- •Array members
- •Array covariance
- •Arrays and the generic IList interface
- •Array initializers
- •Interfaces
- •Interface declarations
- •Interface modifiers
- •Base interfaces
- •Interface body
- •Interface members
- •Interface methods
- •Interface properties
- •Interface events
- •Interface indexers
- •Interface member access
- •Fully qualified interface member names
- •Interface implementations
- •Explicit interface member implementations
- •Interface mapping
- •Interface implementation inheritance
- •Interface re-implementation
- •Abstract classes and interfaces
- •Enums
- •Enum declarations
- •Enum modifiers
- •Enum members
- •The System.Enum type
- •Enum values and operations
- •Delegates
- •Delegate declarations
- •Delegate instantiation
- •Delegate invocation
- •Exceptions
- •Causes of exceptions
- •The System.Exception class
- •How exceptions are handled
- •Common Exception Classes
- •Attributes
- •Attribute classes
- •Attribute usage
- •Positional and named parameters
- •Attribute parameter types
- •Attribute specification
- •Attribute instances
- •Compilation of an attribute
- •Run-time retrieval of an attribute instance
- •Reserved attributes
- •The AttributeUsage attribute
- •The Conditional attribute
- •Conditional Methods
- •Conditional Attribute Classes
- •The Obsolete attribute
- •Unsafe code
- •Unsafe contexts
- •Pointer types
- •Fixed and moveable variables
- •Pointer conversions
- •Pointers in expressions
- •Pointer indirection
- •Pointer member access
- •Pointer element access
- •The address-of operator
- •Pointer increment and decrement
- •Pointer arithmetic
- •Pointer comparison
- •The sizeof operator
- •The fixed statement
- •Stack allocation
- •Dynamic memory allocation
- •Generics
- •Generic class declarations
- •Type parameters
- •The instance type
- •Members of generic classes
- •Static fields in generic classes
- •Static constructors in generic classes
- •Accessing protected members
- •Overloading in generic classes
- •Parameter array methods and type parameters
- •Overriding and generic classes
- •Operators in generic classes
- •Nested types in generic classes
- •Generic struct declarations
- •Generic interface declarations
- •Uniqueness of implemented interfaces
- •Explicit interface member implementations
- •Generic delegate declarations
- •Constructed types
- •Type arguments
- •Open and closed types
- •Base classes and interfaces of a constructed type
- •Members of a constructed type
- •Accessibility of a constructed type
- •Conversions
- •Using alias directives
- •Generic methods
- •Generic method signatures
- •Virtual generic methods
- •Calling generic methods
- •Inference of type arguments
- •Using a generic method with a delegate
- •Constraints
- •Satisfying constraints
- •Member lookup on type parameters
- •Type parameters and boxing
- •Conversions involving type parameters
- •Iterators
- •Iterator blocks
- •Enumerator interfaces
- •Enumerable interfaces
- •Yield type
- •This access
- •Enumerator objects
- •The MoveNext method
- •The Current property
- •The Dispose method
- •Enumerable objects
- •The GetEnumerator method
- •Implementation example
- •Lexical grammar
- •Line terminators
- •White space
- •Comments
- •Unicode character escape sequences
- •Identifiers
- •Keywords
- •Literals
- •Operators and punctuators
- •Pre-processing directives
- •Syntactic grammar
- •Basic concepts
- •Types
- •Expressions
- •Statements
- •Classes
- •Structs
- •Arrays
- •Interfaces
- •Enums
- •Delegates
- •Attributes
- •Generics
- •Grammar extensions for unsafe code
- •Undefined behavior
- •Implementation-defined behavior
- •Unspecified behavior
- •Other Issues
- •Capitalization styles
- •Pascal casing
- •Camel casing
- •All uppercase
- •Capitalization summary
- •Word choice
- •Namespaces
- •Classes
- •Interfaces
- •Enums
- •Static fields
- •Parameters
- •Methods
- •Properties
- •Events
- •Case sensitivity
- •Avoiding type name confusion
- •Documentation Comments
- •Introduction
- •Recommended tags
- •<code>
- •<example>
- •<exception>
- •<list>
- •<para>
- •<param>
- •<paramref>
- •<permission>
- •<remarks>
- •<returns>
- •<seealso>
- •<summary>
- •<value>
- •Processing the documentation file
- •ID string format
- •ID string examples
- •An example
- •C# source code
- •Resulting XML
|
C# LANGUAGE SPECIFICATION |
1 |
void DoCommand(string command) { |
2 |
switch (command.ToLower()) { |
3 |
case "run": |
4 |
DoRun(); |
5 |
break; |
6 |
case "save": |
7 |
DoSave(); |
8 |
break; |
9 |
case "quit": |
10 |
DoQuit(); |
11 |
break; |
12 |
default: |
13 |
InvalidCommand(command); |
14 |
break; |
15}
16}
17end example]
18[Note: Like the string equality operators (§14.9.7), the switch statement is case sensitive and will execute a
19given switch section only if the switch expression string exactly matches a case label constant. end note]
20When the governing type of a switch statement is string, the value null is permitted as a case label
21constant.
22The statement-lists of a switch-block can contain declaration statements (§15.5). The scope of a local
23variable or constant declared in a switch block is the switch block.
24Within a switch block, the meaning of a name used in an expression context shall always be the same
25(§14.5.2.1).
26The statement list of a given switch section is reachable if the switch statement is reachable and at least
27one of the following is true:
28• The switch expression is a non-constant value.
29• The switch expression is a constant value that matches a case label in the switch section.
30• The switch expression is a constant value that doesn’t match any case label, and the switch section
31contains the default label.
32• A switch label of the switch section is referenced by a reachable goto case or goto default
33statement.
34The end point of a switch statement is reachable if at least one of the following is true:
35• The switch statement contains a reachable break statement that exits the switch statement.
36• The switch statement is reachable, the switch expression is a non-constant value, and no default
37label is present.
38• The switch statement is reachable, the switch expression is a constant value that doesn’t match any
39case label, and no default label is present.
4015.8 Iteration statements
41Iteration statements repeatedly execute an embedded statement.
42iteration-statement:
43
44
45
46
while-statement do-statement for-statement foreach-statement
4715.8.1 The while statement
48The while statement conditionally executes an embedded statement zero or more times.
224
Chapter 15 Statements
1 |
while-statement: |
2 |
while ( boolean-expression ) embedded-statement |
3A while statement is executed as follows:
4• The boolean-expression (§14.16) is evaluated.
5• If the boolean expression yields true, control is transferred to the embedded statement. When and if
6control reaches the end point of the embedded statement (possibly from execution of a continue
7statement), control is transferred to the beginning of the while statement.
8• If the boolean expression yields false, control is transferred to the end point of the while statement.
9Within the embedded statement of a while statement, a break statement (§15.9.1) can be used to transfer
10control to the end point of the while statement (thus ending iteration of the embedded statement), and a
11continue statement (§15.9.2) can be used to transfer control to the end point of the embedded statement
12(thus performing another iteration of the while statement).
13The embedded statement of a while statement is reachable if the while statement is reachable and the
14boolean expression does not have the constant value false.
15The end point of a while statement is reachable if at least one of the following is true:
16• The while statement contains a reachable break statement that exits the while statement.
17• The while statement is reachable and the boolean expression does not have the constant value true.
1815.8.2 The do statement
19The do statement conditionally executes an embedded statement one or more times.
20do-statement:
21 |
do embedded-statement while ( boolean-expression ) ; |
22A do statement is executed as follows:
23• Control is transferred to the embedded statement.
24• When and if control reaches the end point of the embedded statement (possibly from execution of a
25continue statement), the boolean-expression (§14.16) is evaluated. If the boolean expression yields
26true, control is transferred to the beginning of the do statement. Otherwise, control is transferred to the
27end point of the do statement.
28Within the embedded statement of a do statement, a break statement (§15.9.1) can be used to transfer
29control to the end point of the do statement (thus ending iteration of the embedded statement), and a
30continue statement (§15.9.2) can be used to transfer control to the end point of the embedded statement
31(thus performing another iteration of the do statement).
32The embedded statement of a do statement is reachable if the do statement is reachable.
33The end point of a do statement is reachable if at least one of the following is true:
34• The do statement contains a reachable break statement that exits the do statement.
35• The end point of the embedded statement is reachable and the boolean expression does not have the
36constant value true.
3715.8.3 The for statement
38The for statement evaluates a sequence of initialization expressions and then, while a condition is true,
39repeatedly executes an embedded statement and evaluates a sequence of iteration expressions.
40for-statement:
41 |
for ( for-initializeropt ; for-conditionopt ; for-iteratoropt ) embedded-statement |
225
|
C# LANGUAGE SPECIFICATION |
1 |
for-initializer: |
2 |
local-variable-declaration |
3 |
statement-expression-list |
4 |
for-condition: |
5 |
boolean-expression |
6 |
for-iterator: |
7 |
statement-expression-list |
8 |
statement-expression-list: |
9 |
statement-expression |
10 |
statement-expression-list , statement-expression |
11The for-initializer, if present, consists of either a local-variable-declaration (§15.5.1) or a list of statement-
12expressions (§15.6) separated by commas. The scope of a local variable declared by a for-initializer starts at
13the local-variable-declarator for the variable and extends to the end of the embedded statement. The scope
14includes the for-condition and the for-iterator.
15The for-condition, if present, shall be a boolean-expression (§14.16).
16The for-iterator, if present, consists of a list of statement-expressions (§15.6) separated by commas.
17A for statement is executed as follows:
18• If a for-initializer is present, the variable initializers or statement expressions are executed in the order
19they are written. This step is only performed once.
20• If a for-condition is present, it is evaluated.
21• If the for-condition is not present or if the evaluation yields true, control is transferred to the embedded
22statement. When and if control reaches the end point of the embedded statement (possibly from
23execution of a continue statement), the expressions of the for-iterator, if any, are evaluated in
24sequence, and then another iteration is performed, starting with evaluation of the for-condition in the
25step above.
26• If the for-condition is present and the evaluation yields false, control is transferred to the end point of
27the for statement.
28Within the embedded statement of a for statement, a break statement (§15.9.1) can be used to transfer
29control to the end point of the for statement (thus ending iteration of the embedded statement), and a
30continue statement (§15.9.2) can be used to transfer control to the end point of the embedded statement
31(thus executing another iteration of the for statement).
32The embedded statement of a for statement is reachable if one of the following is true:
33• The for statement is reachable and no for-condition is present.
34• The for statement is reachable and a for-condition is present and does not have the constant value
35false.
36The end point of a for statement is reachable if at least one of the following is true:
37• The for statement contains a reachable break statement that exits the for statement.
38• The for statement is reachable and a for-condition is present and does not have the constant value
39true.
4015.8.4 The foreach statement
41The foreach statement enumerates the elements of a collection, executing an embedded statement for each
42element of the collection.
43foreach-statement:
44 |
foreach ( type identifier in expression ) embedded-statement |
226
Chapter 15 Statements
1The type and identifier of a foreach statement declare the iteration variable of the statement. The iteration
2variable corresponds to a read-only local variable with a scope that extends over the embedded statement.
3During execution of a foreach statement, the iteration variable represents the collection element for which
4an iteration is currently being performed. A compile-time error occurs if the embedded statement attempts to
5modify the iteration variable (via assignment or the ++ and -- operators) or pass the iteration variable as a
6ref or out parameter.
7The compile-time processing of a foreach statement first determines the collection type, enumerator type
8and element type of the expression. This determination proceeds as follows:
9• If the type X of expression is an array type then there is an implicit reference conversion from X to the
10System.Collections.IEnumerable interface (since System.Array implements this interface).
11The collection type is the System.Collections.IEnumerable interface, the enumerator type is the
12System.Collections.IEnumerator interface and the element type is the element type of the array
13type X.
14• Otherwise, determine whether the type X has an appropriate GetEnumerator method:
15o Perform member lookup on the type X with identifier GetEnumerator and no type arguments. If
16the member lookup does not produce a match or produces an ambiguity or produces a match that is
17not a method group, check for an enumerable interface as described below. It is recommended that a
18warning be issued if member lookup produces anything except a method group or no match.
19o Perform overload resolution using the resulting method group and an empty argument list. If
20overload resolution results in no applicable methods or results in an ambiguity or results in a single
21best method but that method is either static or not public, check for an enumerable interface as
22described below. It is recommended that a warning be issued if overload resolution produces
23anything except an unambiguous public instance method or no applicable methods.
24o If the return type E of the GetEnumerator method is not a class, struct or interface type, an error is
25produced and no further steps are taken.
26o Member lookup is performed on E with the identifier Current and no type arguments. If the
27member lookup produces no match or the result is an error or the result is anything except a public
28instance property that permits reading, an error is produced and no further steps are taken.
29o Member lookup is performed on E with the identifier MoveNext and no type arguments. If the
30member lookup produces no match or the result is an error or the result is anything except a method
31group, an error is produced and no further steps are taken.
32o Overload resolution is performed on the method group with an empty argument list. If overload
33resolution results in no applicable methods or results in an ambiguity or results in a single best
34method but that method is either static or not public, or its return type is not bool, an error is
35produced and no further steps are taken.
36o The collection type is X, the enumerator type is E, and the element type is the type of the Current
37property.
38• Otherwise, check for an enumerable interface:
39o If there is exactly one type T such that there is an implicit conversion from X to the interface
40System.Collections.Generic.IEnumerable<T>, then the collection type is this interface,
41the enumerator type is the interface System.Collections.Generic.IEnumerator<T>, and
42the element type is T.
43o Otherwise, if there is more than one such type T, then an error is produced and no further steps are
44taken.
45o Otherwise, if there is an implicit conversion from X to the System.Collections.IEnumerable
46interface, then the collection type is this interface, the enumerator type is the interface
47System.Collections.IEnumerator, and the element type is object.
227
C# LANGUAGE SPECIFICATION
1o Otherwise, an error is produced and no further steps are taken.
2The above steps, if successful, unambiguously produce a collection type C, enumerator type E and element
3type T. A foreach statement of the form
4foreach (V v in x) embedded-statement
5is then expanded to:
6{
7 |
E e = ((C)(x)).GetEnumerator(); |
8 |
try { |
9 |
while (e.MoveNext()) { |
10 |
V v = (V)(T)e.Current; |
11 |
embedded-statement |
12 |
} |
13 |
} |
14 |
finally { |
15 |
… // Dispose e |
16}
17}
18The variable e is not visible to or accessible to the expression x or the embedded statement or any other
19souce code of the program. The variable v is read-only in the embedded statement. If there is not an explicit
20conversion (§13.2) from T (the element type) to V (the type in the foreach statement), an error is produced
21and no further steps are taken. [Note: If x has the value null, a System.NullReferenceException is
22thrown at run-time. end note]
23The body of the finally block is constructed according to the following steps:
24• First determine whether the enumerator type E has an appropriate Dispose method:
25o Perform member lookup on the type E with identifier Dispose and no type arguments. If the
26member lookup does not produce a match or produces an ambiguity or produces a match that is not
27a method group, check for the System.IDisposable interface as described below. It is
28recommended that a warning be issued if member lookup produces anything except a method group
29or no match.
30o Perform overload resolution using the resulting method group and an empty argument list. If
31overload resolution results in no applicable methods or results in an ambiguity or results in a single
32best method but that method is either static or not public or has a return type other than void, check
33for the System.IDisposable interface as described below. It is recommended that a warning be
34issued if overload resolution produces anything except an unambiguous public instance method with
35void return type or no applicable methods.
36o The finally clause is expanded to:
37finally {
38e.Dispose();
39}
40• Otherwise, check for the System.IDisposable interface:
41o If there is an implicit conversion from E to the System.IDisposable interface, then the finally
42clause is expanded to:
43finally {
44((System.IDisposable)e).Dispose();
45}
46o Otherwise, if E is a sealed type, the finally clause is expanded to an empty block:
47finally {
48}
49o Otherwise, the finally clause is expanded to:
228