Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion standard/basic-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ The ***scope*** of a name is the region of program text within which it is possi
- The scope of a namespace member declared by a *namespace_member_declaration* within a *namespace_declaration* whose fully qualified name is `N`, is the *namespace_body* of every *namespace_declaration* whose fully qualified name is `N` or starts with `N`, followed by a period.
- The scope of a name defined by an *extern_alias_directive* ([§14.4](namespaces.md#144-extern-alias-directives)) extends over the *using_directive*s, *global_attributes*, *statement_list*, and *namespace_member_declaration*s of its immediately containing *compilation_unit* or *namespace_body*. An *extern_alias_directive* does not contribute any new members to the underlying declaration space. In other words, an *extern_alias_directive* is not transitive, but, rather, affects only the *compilation_unit* or *namespace_body* in which it occurs.
- The scope of a name defined or imported by a *using_directive* ([§14.5](namespaces.md#145-using-directives)) extends over the *global_attributes*, *statement_list*, and *namespace_member_declaration*s of the *compilation_unit* or *namespace_body* in which the *using_directive* occurs. A *using_directive* may make zero or more namespace or type names available within a particular *compilation_unit* or *namespace_body*, but does not contribute any new members to the underlying declaration space. In other words, a *using_directive* is not transitive but rather affects only the *compilation_unit* or *namespace_body* in which it occurs.
- The scope of a type parameter declared by a *type_parameter_list* on a *class_declaration* ([§15.2](classes.md#152-class-declarations)) is the *class_base*, *type_parameter_constraints_clause*s, and *class_body* (or *record_class_body*) of that *class_declaration*.
- The scope of a type parameter declared by a *type_parameter_list* in a class declaration ([§15.2](classes.md#152-class-declarations) and §rec-class-general) is the base specification, *type_parameter_constraints_clause*s, and body of that declaration, and, for a record class, its *delimited_parameter_list*.
> *Note*: Unlike members of a class, this scope does not extend to derived classes. *end note*
- The scope of a type parameter declared by a *type_parameter_list* on a *struct_declaration* ([§16.2](structs.md#162-struct-declarations)) is the *struct_interfaces*, *type_parameter_constraints_clause*s, and *struct_body* of that *struct_declaration*.
- The scope of a type parameter declared by a *type_parameter_list* on an *interface_declaration* ([§19.2](interfaces.md#192-interface-declarations)) is the *interface_base*, *type_parameter_constraints_clause*s, and *interface_body* of that *interface_declaration*.
Expand Down
135 changes: 78 additions & 57 deletions standard/classes.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion standard/expressions.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# 12 Expressions

Check warning on line 1 in standard/expressions.md

View workflow job for this annotation

GitHub Actions / word-converter

Markdown to Word Converter - MDC032

Line length 84 > maximum 83; Person person1 = new("Mary", "Smith") { Age = 35 }; // create an immutable record

Check warning on line 2 in standard/expressions.md

View workflow job for this annotation

GitHub Actions / word-converter

Markdown to Word Converter - MDC032

Line length 92 > maximum 83; : anonymous_function_modifier? anonymous_function_signature '=>' anonymous_function_body

Check warning on line 2 in standard/expressions.md

View workflow job for this annotation

GitHub Actions / word-converter

Markdown to Word Converter - MDC032

Line length 85 > maximum 83; Person person2 = person1 with { FirstName = "Jane" }; // copy with FirstName changed

Check warning on line 2 in standard/expressions.md

View workflow job for this annotation

GitHub Actions / word-converter

Markdown to Word Converter - MDC032

Line length 84 > maximum 83; : null_conditional_member_access null_forgiving_operator? '(' argument_list? ')'
## 12.1 General

Check warning on line 3 in standard/expressions.md

View workflow job for this annotation

GitHub Actions / word-converter

Markdown to Word Converter - MDC032

Line length 86 > maximum 83; | 'stackalloc' unmanaged_type? '[' constant_expression? ']' stackalloc_initializer

Check warning on line 3 in standard/expressions.md

View workflow job for this annotation

GitHub Actions / word-converter

Markdown to Word Converter - MDC032

Line length 85 > maximum 83; | null_conditional_element_access null_forgiving_operator? '(' argument_list? ')'

An expression is a sequence of operators and operands. This clause defines the syntax, order of evaluation of operands and operators, and meaning of expressions.

Check warning on line 5 in standard/expressions.md

View workflow job for this annotation

GitHub Actions / word-converter

Markdown to Word Converter - MDC032

Line length 102 > maximum 83; static (int x) => x + 1 // Static anonymous function, explicitly typed, expression body

Check warning on line 6 in standard/expressions.md

View workflow job for this annotation

GitHub Actions / word-converter

Markdown to Word Converter - MDC032

Line length 90 > maximum 83; : anonymous_function_modifier? 'delegate' explicit_anonymous_function_signature? block
## 12.2 Expression classifications

### 12.2.1 General
Expand Down Expand Up @@ -1561,7 +1561,7 @@
- If `e` is zero and the *simple_name* appears within a local variable declaration space ([§7.2](basic-concepts.md#72-declarations)) that directly contains a local variable, parameter (with the exception of discard parameters ([§12.21.2](expressions.md#12212-anonymous-function-signatures))), or constant with name `I`, then the *simple_name* refers to that local variable, parameter or constant and is classified as a variable or value.
- If `e` is zero and the *simple_name* appears within a generic method declaration but outside the *attributes* of its *method_declaration*, and if that declaration includes a type parameter with name `I`, then the *simple_name* refers to that type parameter.
- Otherwise, for each instance type `T` ([§15.3.2](classes.md#1532-the-instance-type)), starting with the instance type of the immediately enclosing type declaration and continuing with the instance type of each enclosing class or struct declaration (if any):
- If the declaration of `T` includes a primary constructor parameter `I` and the reference occurs within the `argument_list` of `T`’s `class_base` or within an initializer of a field, property or event of `T`, the result is the primary constructor parameter `I`.
- If the declaration of `T` includes a primary constructor parameter `I` and the reference occurs within the *argument_list* of `T`’s *record_class_base* or within an initializer of a field, property or event of `T`, the result is the primary constructor parameter `I`.
- Otherwise, if `e` is zero and the declaration of `T` includes a type parameter with name `I`, then the *simple_name* refers to that type parameter.
- Otherwise, if a member lookup ([§12.5](expressions.md#125-member-lookup)) of `I` in `T` with `e` type arguments produces a match:
- If `T` is the instance type of the immediately enclosing class or struct type and the lookup identifies one or more methods, the result is a method group with an associated instance expression of `this`. If a type argument list was specified, it is used in calling a generic method ([§12.8.10.2](expressions.md#128102-method-invocations)).
Expand Down
2 changes: 1 addition & 1 deletion standard/interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ The ***base interface***s of an interface are the explicit base interfaces and t
>
> *end example*

Members inherited from a constructed generic type are inherited after type substitution. That is, any constituent types in the member have the base class declaration’s type parameters replaced with the corresponding type arguments used in the *class_base* specification.
Members inherited from a constructed generic type are inherited after type substitution. That is, any constituent types in the member have the base class declaration’s type parameters replaced with the corresponding type arguments used in the *class_base* or *record_class_base* specification.

> *Example*: In the following code
>
Expand Down
24 changes: 21 additions & 3 deletions standard/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -719,11 +719,29 @@ Whenever a constructed type or generic method is referenced, the supplied type a
- `A` is a value type, since all value types have a public default constructor ([§8.3.3](types.md#833-default-constructors)).
- `A` is a type parameter having the constructor constraint ([§15.2.5](classes.md#1525-type-parameter-constraints)).
- `A` is a type parameter having the value type constraint ([§15.2.5](classes.md#1525-type-parameter-constraints)).
- `A` is a `class` that is not abstract and contains an explicitly declared public constructor with no parameters.
- `A` is not `abstract` and has a default constructor ([§15.11.5](classes.md#15115-default-constructors)).
- `A` is a class that is not abstract and has a public parameterless instance constructor, whether explicitly declared or provided by the implementation ([§15.11.5](classes.md#15115-default-constructors) and §rec-class-pos-mem-pricon).

A compile-time error occurs if one or more of a type parameter’s constraints are not satisfied by the given type arguments.

> *Example*: Both a default constructor and a parameterless primary constructor satisfy a constructor constraint:
>
> <!-- Example: {template:"standalone-lib-without-using", name:"RecordConstructorConstraint"} -->
> ```csharp
> public record Default;
> public record Primary();
> public class Factory<T> where T : class, new()
> {
> public static T Create() => new T();
> }
> public class Test
> {
> public object A() => Factory<Default>.Create();
> public object B() => Factory<Primary>.Create();
> }
> ```
>
> *end example*

Since type parameters are not inherited, constraints are never inherited either.

> *Example*: In the following, `D` needs to specify the constraint on its type parameter `T` so that `T` satisfies the constraint imposed by the base `class` `B<T>`. In contrast, `class` `E` need not specify a constraint, because `List<T>` implements `IEnumerable` for any `T`.
Expand Down Expand Up @@ -817,7 +835,7 @@ The type `dynamic` is considered identical to `object` except in the following r
- Type inference ([§12.6.3](expressions.md#1263-type-inference)) will prefer `dynamic` over `object` if both are candidates.
- `dynamic` cannot be used as
- the type in an *object_creation_expression* ([§12.8.17.2](expressions.md#128172-object-creation-expressions))
- a *class_base* ([§15.2.4](classes.md#1524-class-base-specification))
- a *class_base* ([§15.2.4](classes.md#1524-class-base-specification)) or *record_class_base* (§rec-class-class-base-specification)
- a *predefined_type* in a *member_access* ([§12.8.7.1](expressions.md#12871-general))
- the operand of the `typeof` operator
- an attribute argument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
⎜ ⎜ ⎛
⎜ ⎜ ⎜ namespace_member_declaration
⎜ ⎜ ⎜ ⎛
⎜ ⎜ ⎜ ⎜ non_record_class_declaration
⎜ ⎜ ⎜ ⎜ class_declaration
⎜ ⎜ ⎜ ⎜ partial
⎜ ⎜ ⎜ ⎜ class
⎜ ⎜ ⎜ ⎜ ⎛
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(prog (compilation_unit (using_directive (using_namespace_directive using (namespace_name (identifier System)) ;)) (using_directive (using_namespace_directive using (namespace_name (namespace_or_type_name (identifier System) . (identifier Runtime) . (identifier CompilerServices))) ;)) (statement_list (statement (expression_statement (statement_expression (invocation_expression (primary_expression (member_access (primary_expression (identifier Console)) . (identifier WriteLine))) ( (argument_list (interpolated_regular_string_expression 〔$"〕 { (regular_interpolation (invocation_expression (primary_expression (identifier GetName)) ( ))) } 〔: args[0] = 〕 { (regular_interpolation (element_access (primary_expression (identifier args)) [ (argument_list (literal 0)) ])) } 〔"〕)) ))) ;)) (statement (expression_statement (statement_expression (invocation_expression (primary_expression (member_access (primary_expression (identifier Program)) . (identifier Main))) ( (argument_list (identifier args)) ))) ;)) (statement (local_function_declaration (return_type (class_type string)) (local_function_header (identifier GetName) ( (parameter_list (fixed_parameter (attributes (attribute_section [ (attribute_list (identifier CallerMemberName)) ])) (type (class_type string)) (identifier memberName) (default_argument = (expression (literal ""))))) )) (local_function_body (block { (statement_list (return_statement return (expression (identifier memberName)) ;)) }))))) (namespace_member_declaration (non_record_class_declaration partial class (identifier Program) (class_body { (class_member_declaration (method_declaration (method_modifiers (method_modifier (ref_method_modifier public)) (method_modifier (ref_method_modifier static))) (return_type void) (method_header (member_name (identifier Main)) ( (parameter_list (fixed_parameter (type (array_type (non_array_type (class_type string)) (rank_specifier [ ]))) (identifier args))) )) (method_body (block { (statement_list (expression_statement (statement_expression (invocation_expression (primary_expression (member_access (primary_expression (identifier Console)) . (identifier WriteLine))) ( (argument_list (interpolated_regular_string_expression 〔$"〕 〔Main: args[0] = 〕 { (regular_interpolation (element_access (primary_expression (identifier args)) [ (argument_list (literal 0)) ])) } 〔"〕)) ))) ;)) })))) })))))
(prog (compilation_unit (using_directive (using_namespace_directive using (namespace_name (identifier System)) ;)) (using_directive (using_namespace_directive using (namespace_name (namespace_or_type_name (identifier System) . (identifier Runtime) . (identifier CompilerServices))) ;)) (statement_list (statement (expression_statement (statement_expression (invocation_expression (primary_expression (member_access (primary_expression (identifier Console)) . (identifier WriteLine))) ( (argument_list (interpolated_regular_string_expression 〔$"〕 { (regular_interpolation (invocation_expression (primary_expression (identifier GetName)) ( ))) } 〔: args[0] = 〕 { (regular_interpolation (element_access (primary_expression (identifier args)) [ (argument_list (literal 0)) ])) } 〔"〕)) ))) ;)) (statement (expression_statement (statement_expression (invocation_expression (primary_expression (member_access (primary_expression (identifier Program)) . (identifier Main))) ( (argument_list (identifier args)) ))) ;)) (statement (local_function_declaration (return_type (class_type string)) (local_function_header (identifier GetName) ( (parameter_list (fixed_parameter (attributes (attribute_section [ (attribute_list (identifier CallerMemberName)) ])) (type (class_type string)) (identifier memberName) (default_argument = (expression (literal ""))))) )) (local_function_body (block { (statement_list (return_statement return (expression (identifier memberName)) ;)) }))))) (namespace_member_declaration (class_declaration partial class (identifier Program) (class_body { (class_member_declaration (method_declaration (method_modifiers (method_modifier (ref_method_modifier public)) (method_modifier (ref_method_modifier static))) (return_type void) (method_header (member_name (identifier Main)) ( (parameter_list (fixed_parameter (type (array_type (non_array_type (class_type string)) (rank_specifier [ ]))) (identifier args))) )) (method_body (block { (statement_list (expression_statement (statement_expression (invocation_expression (primary_expression (member_access (primary_expression (identifier Console)) . (identifier WriteLine))) ( (argument_list (interpolated_regular_string_expression 〔$"〕 〔Main: args[0] = 〕 { (regular_interpolation (element_access (primary_expression (identifier args)) [ (argument_list (literal 0)) ])) } 〔"〕)) ))) ;)) })))) })))))
Loading