- •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
Chapter 17 Classes
1generic method-declaration for an explicit interface member implementation inherits any constraints from
2the constraints on the interface method. Similarly, a method declaration with the override modifier shall
3not have any type-parameter-constraints-clauses and the constraints of the method’s type parameters are
4inherited from the virtual method being overridden. Generic methods are fully specified in §26.6.
5The optional formal-parameter-list specifies the parameters of the method (§17.5.1).
6The return-type and each of the types referenced in the formal-parameter-list of a method shall be at least as
7accessible as the method itself (§10.5.4).
8For abstract and extern methods, the method-body consists simply of a semicolon. For all other
9methods, the method-body consists of a block, which specifies the statements to execute when the method is
10invoked.
11The name, the number of type parameters, and the formal parameter list of a method define the signature
12(§10.6) of the method. Specifically, the signature of a method consists of its name, the number of its type
13parameters, and the number, parameter-modifiers, and types of its formal parameters. The return type is not
14part of a method’s signature, nor are the names of the formal parameters, the names of the type parameters,
15or the constraints. When a formal parameter type references a type parameter of the method, the ordinal
16position of the type parameter (not the name of the type parameter) is used for type equivalence.
17The name of a method shall differ from the names of all other non-methods declared in the same class. In
18addition, the signature of a method shall differ from the signatures of all other methods declared in the same
19class, and two methods declared in the same class shall not have signatures that differ solely by ref and
20out.
2117.5.1 Method parameters
22The parameters of a method, if any, are declared by the method’s formal-parameter-list.
23formal-parameter-list:
24 |
fixed-parameters |
25 |
fixed-parameters , parameter-array |
26 |
parameter-array |
27 |
fixed-parameters: |
28 |
fixed-parameter |
29 |
fixed-parameters , fixed-parameter |
30 |
fixed-parameter: |
31 |
attributesopt parameter-modifieropt type identifier |
32 |
parameter-modifier: |
33 |
ref |
34out
35parameter-array:
36 |
attributesopt params array-type identifier |
37The formal parameter list consists of one or more comma-separated parameters of which only the last can be
38a parameter-array.
39A fixed-parameter consists of an optional set of attributes (§24), an optional ref or out modifier, a type,
40and an identifier. Each fixed-parameter declares a parameter of the given type with the given name.
41A parameter-array consists of an optional set of attributes (§24), a params modifier, an array-type, and an
42identifier. A parameter array declares a single parameter of the given array type with the given name. The
43array-type of a parameter array shall be a single-dimensional array type (§19.1). In a method invocation, a
44parameter array permits either a single argument of the given array type to be specified, or it permits zero or
45more arguments of the array element type to be specified. Parameter arrays are described further in
46§17.5.1.4.
279
C# LANGUAGE SPECIFICATION
1A method declaration creates a separate declaration space (§10.3) for type parameters, formal parameters,
2local variables, and local constants. Names are introduced into this declaration space by the type parameter
3list and formal parameter list of the method and by local variable declarations and by local constant
4declarations in the block of the method. All names in the declaration space of a method shall be unique;
5otherwise, a compile-time error results.
6A method invocation (§14.5.5.1) creates a copy, specific to that invocation, of the formal parameters and
7local variables of the method, and the argument list of the invocation assigns values or variable references to
8the newly created formal parameters. Within the block of a method, formal parameters can be referenced by
9their identifiers in simple-name expressions (§14.5.2).
10There are four kinds of formal parameters:
11• Value parameters, which are declared without any modifiers.
12• Reference parameters, which are declared with the ref modifier.
13• Output parameters, which are declared with the out modifier.
14• Parameter arrays, which are declared with the params modifier.
15[Note: As described in §10.6, the ref and out modifiers are part of a method’s signature, but the params
16modifier is not. end note]
1717.5.1.1 Value parameters
18A parameter declared with no modifiers is a value parameter. A value parameter corresponds to a local
19variable that gets its initial value from the corresponding argument supplied in the method invocation.
20When a formal parameter is a value parameter, the corresponding argument in a method invocation shall be
21an expression of a type that is implicitly convertible (§13.1) to the formal parameter type.
22A method is permitted to assign new values to a value parameter. Such assignments only affect the local
23storage location represented by the value parameter—they have no effect on the actual argument given in the
24method invocation.
2517.5.1.2 Reference parameters
26A parameter declared with a ref modifier is a reference parameter. Unlike a value parameter, a reference
27parameter does not create a new storage location. Instead, a reference parameter represents the same storage
28location as the variable given as the argument in the method invocation.
29When a formal parameter is a reference parameter, the corresponding argument in a method invocation shall
30consist of the keyword ref followed by a variable-reference (§12.3.3.27) of the same type as the formal
31parameter. A variable shall be definitely assigned before it can be passed as a reference parameter.
32Within a method, a reference parameter is always considered definitely assigned.
33[Example: The example
34using System;
35class Test
36{
37 |
static |
void Swap(ref int x, ref int y) { |
38 |
int |
temp = x; |
39 |
x = |
y; |
40 |
y = temp; |
|
41 |
} |
|
42 |
static void Main() { |
|
43 |
int i = 1, j = 2; |
|
44 |
Swap(ref i, ref j); |
|
45 |
Console.WriteLine("i = {0}, j = {1}", i, j); |
|
46}
47}
280
Chapter 17 Classes
1produces the output
2i = 2, j = 1
3For the invocation of Swap in Main, x represents i and y represents j. Thus, the invocation has the effect of
4swapping the values of i and j. end example]
5In a method that takes reference parameters, it is possible for multiple names to represent the same storage
6location. [Example: In the following code
7class A
8{
9 |
string s; |
10 |
void F(ref string a, ref string b) { |
11 |
s = "One"; |
12 |
a = "Two"; |
13 |
b = "Three"; |
14 |
} |
15 |
void G() { |
16 |
F(ref s, ref s); |
17}
18}
19the invocation of F in G passes a reference to s for both a and b. Thus, for that invocation, the names s, a,
20and b all refer to the same storage location, and the three assignments all modify the instance field s. end
21example]
2217.5.1.3 Output parameters
23A parameter declared with an out modifier is an output parameter. Similar to a reference parameter, an
24output parameter does not create a new storage location. Instead, an output parameter represents the same
25storage location as the variable given as the argument in the method invocation.
26When a formal parameter is an output parameter, the corresponding argument in a method invocation shall
27consist of the keyword out followed by a variable-reference (§12.3.3.27) of the same type as the formal
28parameter. A variable need not be definitely assigned before it can be passed as an output parameter, but
29following an invocation where a variable was passed as an output parameter, the variable is considered
30definitely assigned.
31Within a method, just like a local variable, an output parameter is initially considered unassigned and shall
32be definitely assigned before its value is used.
33Every output parameter of a method shall be definitely assigned before the method returns.
34Output parameters are typically used in methods that produce multiple return values. [Example:
35using System;
36class Test
37{
38 |
static void SplitPath(string path, out string dir, out string name) { |
39 |
int i = path.Length; |
40 |
while (i > 0) { |
41 |
char ch = path[i – 1]; |
42 |
if (ch == '\\' || ch == '/' || ch == ':') break; |
43 |
i--; |
44 |
} |
45 |
dir = path.Substring(0, i); |
46 |
name = path.Substring(i); |
47 |
} |
48 |
static void Main() { |
49 |
string dir, name; |
50 |
SplitPath(@"c:\Windows\System\hello.txt", out dir, out name); |
51 |
Console.WriteLine(dir); |
52 |
Console.WriteLine(name); |
53}
54}
281
C# LANGUAGE SPECIFICATION
1The example produces the output:
2c:\Windows\System\
3hello.txt
4Note that the dir and name variables can be unassigned before they are passed to SplitPath, and that they
5are considered definitely assigned following the call. end example]
617.5.1.4 Parameter arrays
7A parameter declared with a params modifier is a parameter array. If a formal parameter list includes a
8parameter array, it shall be the last parameter in the list and it shall be of a single-dimensional array type.
9[Example: The types string[] and string[][,] can be used as the type of a parameter array, but the
10type string[,] can not. end example] It is not possible to combine the params modifier with the
11modifiers ref and out.
12A parameter array permits arguments to be specified in one of two ways in a method invocation:
13• The argument given for a parameter array can be a single expression that is implicitly convertible
14(§13.1) to the parameter array type. In this case, the parameter array acts precisely like a value
15parameter.
16• Alternatively, the invocation can specify zero or more arguments for the parameter array, where each
17argument is an expression that is implicitly convertible (§13.1) to the element type of the parameter
18array. In this case, the invocation creates an instance of the parameter array type with a length
19corresponding to the number of arguments, initializes the elements of the array instance with the given
20argument values, and uses the newly created array instance as the actual argument.
21Except for allowing a variable number of arguments in an invocation, a parameter array is precisely
22equivalent to a value parameter (§17.5.1.1) of the same type.
23[Example: The example
24using System;
25class Test
26{
27 |
static void F(params int[] args) { |
28 |
Console.Write("Array contains {0} elements:", args.Length); |
29 |
foreach (int i in args) |
30 |
Console.Write(" {0}", i); |
31 |
Console.WriteLine(); |
32 |
} |
33 |
static void Main() { |
34 |
int[] arr = {1, 2, 3}; |
35 |
F(arr); |
36 |
F(10, 20, 30, 40); |
37 |
F(); |
38}
39}
40produces the output
41Array contains 3 elements: 1 2 3
42Array contains 4 elements: 10 20 30 40
43Array contains 0 elements:
44The first invocation of F simply passes the array arr as a value parameter. The second invocation of F
45automatically creates a four-element int[] with the given element values and passes that array instance as a
46value parameter. Likewise, the third invocation of F creates a zero-element int[] and passes that instance
47as a value parameter. The second and third invocations are precisely equivalent to writing:
48F(new int[] {10, 20, 30, 40});
49F(new int[] {});
50end example]
282
Chapter 17 Classes
1When performing overload resolution, a method with a parameter array might be applicable, either in its
2normal form or in its expanded form (§14.4.2.1). The expanded form of a method is available only if the
3normal form of the method is not applicable and only if a method with the same signature as the expanded
4form is not already declared in the same type.
5[Example: The example
6using System;
7class Test
8{
9 |
static void F(params object[] a) { |
||
10 |
Console.WriteLine("F(object[])"); |
||
11 |
} |
|
|
12 |
static void F() { |
||
13 |
Console.WriteLine("F()"); |
||
14 |
} |
|
|
15 |
static void F(object a0, object a1) { |
||
16 |
Console.WriteLine("F(object,object)"); |
||
17 |
} |
|
|
18 |
static void Main() { |
||
19 |
F(); |
|
|
20 |
F(1); |
|
|
21 |
F(1, 2); |
|
|
22 |
F(1, |
2, |
3); |
23 |
F(1, 2, 3, 4); |
||
24}
25}
26produces the output
27F();
28F(object[]);
29F(object,object);
30F(object[]);
31F(object[]);
32In the example, two of the possible expanded forms of the method with a parameter array are already
33included in the class as regular methods. These expanded forms are therefore not considered when
34performing overload resolution, and the first and third method invocations thus select the regular methods.
35When a class declares a method with a parameter array, it is not uncommon to also include some of the
36expanded forms as regular methods. By doing so it is possible to avoid the allocation of an array instance
37that occurs when an expanded form of a method with a parameter array is invoked. end example]
38When the type of a parameter array is object[], a potential ambiguity arises between the normal form of
39the method and the expended form for a single object parameter. The reason for the ambiguity is that an
40object[] is itself implicitly convertible to type object. The ambiguity presents no problem, however,
41since it can be resolved by inserting a cast if needed.
42[Example: The example
43using System;
44class Test
45{
46 |
static void F(params object[] args) { |
47 |
foreach (object o in args) { |
48 |
Console.Write(o.GetType().FullName); |
49 |
Console.Write(" "); |
50 |
} |
51 |
Console.WriteLine(); |
52 |
} |
283
