Skip to content

Commit 09a4851

Browse files
committed
Some edits.
1 parent 42bd8fd commit 09a4851

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

docs/csharp/language-reference/operators/nameof.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,20 @@ A `nameof` expression produces the name of a variable, type, or member as the st
1616

1717
:::code language="csharp" interactive="try-dotnet-method" source="snippets/shared/NameOfOperator.cs" id="Examples":::
1818

19-
You can use a `nameof` expression to make the argument-checking code more maintainable:
19+
The preceding example using `List<>` is supported in C# 14 and later. You can use a `nameof` expression to make the argument-checking code more maintainable:
2020

21-
:::code language="csharp" interactive="try-dotnet-method" source="snippets/shared/NameOfOperator.cs" id="ExceptionMessage":::
21+
:::code language="csharp" source="snippets/shared/NameOfOperator.cs" id="ExceptionMessage":::
2222

2323
Beginning with C# 11, you can use a `nameof` expression with a method parameter inside an [attribute](../../advanced-topics/reflection-and-attributes/index.md) on a method or its parameter. The following code shows how to do that for an attribute on a method, a local function, and the parameter of a lambda expression:
2424

25-
:::code language="csharp" interactive="try-dotnet-method" source="snippets/shared/NameOfOperator.cs" id="SnippetNameOfParameter":::
25+
:::code language="csharp" source="snippets/shared/NameOfOperator.cs" id="SnippetNameOfParameter":::
2626

2727
A `nameof` expression with a parameter is useful when you use the [nullable analysis attributes](../attributes/nullable-analysis.md) or the [CallerArgumentExpression attribute](../attributes/caller-information.md#argument-expressions).
2828

2929
When the operand is a [verbatim identifier](../tokens/verbatim.md), the `@` character isn't part of the name, as the following example shows:
3030

3131
:::code language="csharp" interactive="try-dotnet-method" source="snippets/shared/NameOfOperator.cs" id="Verbatim":::
3232

33-
Beginning with C# 14, the argument can be an unbound generic type, such as `List<>`. The `nameof(List<>)` expression evaluates to `List`. If you use a closed generic type, such as `List<int>`, the output is the generic type, not the closed instantiation: `List`.
34-
3533
## C# language specification
3634

3735
For more information, see the [Nameof expressions](~/_csharpstandard/standard/expressions.md#12823-the-nameof-operator) section of the [C# language specification](~/_csharpstandard/standard/README.md), and the [C# 11 - Extended `nameof` scope](~/_csharplang/proposals/csharp-11.0/extended-nameof-scope.md) feature specification.

docs/csharp/language-reference/operators/snippets/shared/NameOfOperator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public static void Examples()
77
// <SnippetExamples>
88
Console.WriteLine(nameof(System.Collections.Generic)); // output: Generic
99
Console.WriteLine(nameof(List<int>)); // output: List
10+
Console.WriteLine(nameof(List<>)); // output: List
1011
Console.WriteLine(nameof(List<int>.Count)); // output: Count
1112
Console.WriteLine(nameof(List<int>.Add)); // output: Add
1213

docs/csharp/language-reference/operators/snippets/shared/operators.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net8.0</TargetFramework>
5+
<TargetFramework>net9.0</TargetFramework>
66
<Nullable>enable</Nullable>
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
88
<ImplicitUsings>true</ImplicitUsings>
99
<NoWarn>7022</NoWarn>
10+
<LangVersion>preview</LangVersion>
1011
</PropertyGroup>
1112

1213
<ItemGroup>

0 commit comments

Comments
 (0)