- •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
1The text within documentation comments must be well formed according to the rules of XML
2(http://www.w3.org/TR/REC-xml). If the XML is ill formed, a warning is generated and the documentation
3file will contain a comment saying that an error was encountered.
4Although developers are free to create their own set of tags, a recommended set is defined in §E.2. Some of
5the recommended tags have special meanings:
6• The <param> tag is used to describe parameters. If such a tag is used, the documentation generator must
7verify that the specified parameter exists and that all parameters are described in documentation
8comments. If such verification fails, the documentation generator issues a warning.
9• The cref attribute can be attached to any tag to provide a reference to a code element. The
10documentation generator must verify that this code element exists. If the verification fails, the
11documentation generator issues a warning. When looking for a name described in a cref attribute, the
12documentation generator must respect namespace visibility according to using statements appearing
13within the source code.
14• The <summary> tag is intended to be used by a documentation viewer to display additional information
15about a type or member.
16Note carefully that the documentation file does not provide full information about the type and members (for
17example, it does not contain any type information). To get such information about a type or member, the
18documentation file must be used in conjunction with reflection on the actual type or member.
19E.2 Recommended tags
20The documentation generator must accept and process any tag that is valid according to the rules of XML.
21The following tags provide commonly used functionality in user documentation. (Of course, other tags are
22possible.)
23
Tag |
Reference |
Purpose |
|
|
|
<c> |
§E.2.1 |
Set text in a code-like font |
|
|
|
<code> |
§E.2.2 |
Set one or more lines of source code or program output |
|
|
|
<example> |
§E.2.3 |
Indicate an example |
|
|
|
<exception> |
§E.2.4 |
Identifies the exceptions a method can throw |
|
|
|
<list> |
§E.2.5 |
Create a list or table |
|
|
|
<para> |
§E.2.6 |
Permit structure to be added to text |
|
|
|
<param> |
§E.2.7 |
Describe a parameter for a method or constructor |
|
|
|
<paramref> |
§E.2.8 |
Identify that a word is a parameter name |
|
|
|
<permission> |
§E.2.9 |
Document the security accessibility of a member |
|
|
|
<remarks> |
§E.2.10 |
Describe a type |
|
|
|
<returns> |
§E.2.11 |
Describe the return value of a method |
|
|
|
<see> |
§E.2.12 |
Specify a link |
|
|
|
<seealso> |
§E.2.13 |
Generate a See Also entry |
|
|
|
<summary> |
§E.2.14 |
Describe a member of a type |
|
|
|
<value> |
§E.2.15 |
Describe a property |
|
|
|
24
512
Annex E Documentation Comments
1E.2.1 <c>
2This tag provides a mechanism to indicate that a fragment of text within a description should be set in a
3special font such as that used for a block of code. For lines of actual code, use <code> (§E.2.2).
4Syntax:
5<c>text to be set like code</c>
6Example:
7/// <remarks>
8/// Class <c>Point</c> models a point in a two-dimensional plane.
9/// </remarks>
10public class Point
11{
12…
13}
14E.2.2 <code>
15This tag is used to set one or more lines of source code or program output in some special font. For small
16code fragments in narrative, use <c> (§E.2.1).
17Syntax:
18<code>source code or program output</code>
19Example:
20/// <summary>
21/// Changes the Point's location by the given x- and y-offsets.
22/// </summary>
23/// <example>
24/// The following code:
25 |
/// |
<code> |
26 |
/// |
Point p = new Point(3,5); |
27 |
/// |
p.Translate(-1,3); |
28 |
/// |
</code> |
29/// results in <c>p</c>'s having the value (2,8).
30/// </example>
31public void Translate(int xor, int yor) {
32 |
X += xor; |
33Y += yor;
34}
35E.2.3 <example>
36This tag allows example code within a comment, to specify how a method or other library member might be
37used. Ordinarily, this would also involve use of the tag <code> (§E.2.2) as well.
38Syntax:
39<example>description</example>
40Example:
41See <code> (§E.2.2) for an example.
42E.2.4 <exception>
43This tag provides a way to document the exceptions a method can throw.
44Syntax:
45<exception cref="member">description</exception>
46where
47cref="member"
513
C# LANGUAGE SPECIFICATION
1The name of a member. The documentation generator checks that the given member exists and
2translates member to the canonical element name in the documentation file.
3description
4A description of the circumstances in which the exception is thrown.
5Example:
6public class DataBaseOperations
7{
8 |
/// <exception cref="MasterFileFormatCorruptException"></exception> |
9 |
/// <exception cref="MasterFileLockedOpenException"></exception> |
10 |
public static void ReadRecord(int flag) { |
11 |
if (flag == 1) |
12 |
throw new MasterFileFormatCorruptException(); |
13 |
else if (flag == 2) |
14 |
throw new MasterFileLockedOpenException(); |
15 |
// … |
16}
17}
18E.2.5 <list>
19This tag is used to create a list or table of items. It can contain a <listheader> block to define the heading
20row of either a table or definition list. (When defining a table, only an entry for term in the heading need be
21supplied.)
22Each item in the list is specified with an <item> block. When creating a definition list, both term and
23description must be specified. However, for a table, bulleted list, or numbered list, only description
24need be specified.
25Syntax:
26<list type="style">
27 |
<listheader> |
28 |
<term>term</term> |
29 |
<description>description</description> |
30 |
</listheader> |
31 |
<item> |
32 |
<term>term</term> |
33 |
<description>description</description> |
34 |
</item> |
35 |
… |
36 |
<item> |
37 |
<term>term</term> |
38 |
<description>description</description> |
39</item>
40</list>
41where
42style
43The style of the list. Must be bullet, number, or table.
44term
45The term to define, whose definition is in description.
46description
47Either an item in a bullet or numbered list, or the definition of a term.
48Example:
514
Annex E Documentation Comments
1public class MyClass
2{
3 |
/// <remarks> |
|
4 |
/// Here is an example of a bulleted list: |
|
5 |
/// |
<list type="bullet"> |
6 |
/// |
<item> |
7 |
/// |
<description>First item.</description> |
8 |
/// |
</item> |
9 |
/// |
<item> |
10 |
/// |
<description>Second item.</description> |
11 |
/// |
</item> |
12 |
/// |
</list> |
13 |
/// </remarks> |
|
14 |
public static void Main () { |
|
15 |
… |
|
16}
17}
18E.2.6 <para>
19This tag is for use inside other tags, such as <remarks> (§E.2.10) or <returns> (§E.2.11), and permits
20structure to be added to text.
21Syntax:
22<para>content</para>
23where
24content
25The text of the paragraph.
26Example:
27/// <summary>
28 |
/// |
<para> |
29 |
/// |
This is the entry point of the Point class testing program. |
30 |
/// |
</para> |
31 |
/// |
<para> |
32/// This program tests each method and operator, and is intended
33/// to be run after any non-trvial maintenance has been performed
34/// on the Point class.
35 /// </para>
36/// </summary>
37public static void Main() {
38…
39}
40E.2.7 <param>
41This tag is used to describe a parameter for a method, constructor, or indexer.
42Syntax:
43<param name="name">description</param>
44where
45name
46The name of the parameter.
47description
48A description of the parameter.
49Example:
515