You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixesdotnet#44182
Add that `nameof` now supports open generic types.
This is the first C# 14 feature I've added, so create the C# 14 file, and update the language version tables accordingly.
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/configure-language-version.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: Configure language version
3
3
description: Learn how to override the default C# language version manually. The C# compiler can support any language version up to the version in the installed SDK.
4
4
ms.custom: "updateeachrelease"
5
-
ms.date: 09/17/2024
5
+
ms.date: 01/31/2025
6
6
---
7
7
8
8
# Configure C# language version
@@ -17,7 +17,7 @@ If you need a specific language version that differs from the one automatically
17
17
18
18
> [!WARNING]
19
19
>
20
-
> Setting the `LangVersion` element to `latest` is discouraged. The `latest` setting means the installed compiler uses its latest version. That can change from machine to machine, making builds unreliable. In addition, it enables language features that may require runtime or library features not included in the current SDK.
20
+
> Setting the `LangVersion` element to `latest` is discouraged. The `latest` setting means the installed compiler uses its latest version. The value of `latest`can change from machine to machine, making builds unreliable. In addition, it enables language features that might require runtime or library features not included in the current SDK.
21
21
22
22
If you must specify your C# version explicitly, you can do so in several ways:
23
23
@@ -28,19 +28,19 @@ If you must specify your C# version explicitly, you can do so in several ways:
28
28
> [!TIP]
29
29
> You can see the language version in Visual Studio in the project properties page. Under the *Build* tab, the *Advanced* pane displays the version selected.
30
30
>
31
-
> To know what language version you're currently using, put `#error version` (case sensitive) in your code. This makes the compiler report a compiler error, CS8304, with a message containing the compiler version being used and the current selected language version. For more information about this pragma, see [#error (C# Reference)](preprocessor-directives.md#error-and-warning-information).
31
+
> To know what language version you're currently using, put `#error version` (case sensitive) in your code. This pragma makes the compiler report a compiler error, CS8304, with a message containing the compiler version used and the current selected language version. For more information about this pragma, see [#error (C# Reference)](preprocessor-directives.md#error-and-warning-information).
32
32
33
33
## Edit the project file
34
34
35
-
You can set the language version in your project file. For example, if you explicitly want access to preview features, add an element like this:
35
+
You can set the language version in your project file. For example, if you explicitly want access to preview features, add an element like the following example:
36
36
37
37
```xml
38
38
<PropertyGroup>
39
39
<LangVersion>preview</LangVersion>
40
40
</PropertyGroup>
41
41
```
42
42
43
-
The value `preview` uses the latest available preview C# language version that your compiler supports.
43
+
The value `preview` uses the latest available preview C# language version your compiler supports.
44
44
45
45
## Configure multiple projects
46
46
@@ -58,7 +58,7 @@ Builds in all subdirectories of the directory containing that file now use the p
58
58
59
59
> [!NOTE]
60
60
>
61
-
> The versions for C# and VB are different. Don't use the *Directory.Build.Props* file for a folder where subdirectories contain projects for both languages. The versions won't match.
61
+
> The versions for C# and VB are different. Don't use the *Directory.Build.Props* file for a folder where subdirectories contain projects for both languages. The versions don't match.
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/operators/nameof.md
+7-5
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: "The nameof expression - evaluate the text name of a symbol"
3
3
description: "The C# `nameof` expression produces the name of its operand. You use it whenever you need to use the name of a symbol as text"
4
-
ms.date: 11/28/2022
4
+
ms.date: 01/31/2025
5
5
f1_keywords:
6
6
- "nameof_CSharpKeyword"
7
7
- "nameof"
@@ -14,21 +14,23 @@ helpviewer_keywords:
14
14
15
15
A `nameof` expression produces the name of a variable, type, or member as the string constant. A `nameof` expression is evaluated at compile time and has no effect at run time. When the operand is a type or a namespace, the produced name isn't [fully qualified](~/_csharpstandard/standard/basic-concepts.md#783-fully-qualified-names). The following example shows the use of a `nameof` expression:
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:
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).
28
28
29
29
When the operand is a [verbatim identifier](../tokens/verbatim.md), the `@` character isn't part of the name, as the following example shows:
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`.
description: Get an overview of the new features in C# 13.
4
+
ms.date: 01/31/2025
5
+
ms.topic: whats-new
6
+
---
7
+
# What's new in C# 14
8
+
9
+
C# 14 includes the following new features. You can try these features using the latest [Visual Studio 2022](https://visualstudio.microsoft.com/vs/preview/) version or the [.NET 10 SDK](https://dotnet.microsoft.com/download/dotnet):
C# 14 includes the [`field`](#the-field-keyword) contextual keyword as a preview feature.
14
+
15
+
C# 14 is supported on **.NET 10**. For more information, see [C# language versioning](../language-reference/configure-language-version.md).
16
+
17
+
You can download the latest .NET 10 SDK from the [.NET downloads page](https://dotnet.microsoft.com/download). You can also download [Visual Studio 2022](https://visualstudio.microsoft.com/vs/), which includes the .NET 10 SDK.
18
+
19
+
New features are added to the "What's new in C#" page when they're available in public preview releases. The [working set](https://github.com/dotnet/roslyn/blob/main/docs/Language%20Feature%20Status.md#working-set) section of the [roslyn feature status page](https://github.com/dotnet/roslyn/blob/main/docs/Language%20Feature%20Status.md) tracks when upcoming features are merged into the main branch.
20
+
21
+
You can find any breaking changes introduced in C# 14 in our article on [breaking changes](~/_roslyn/docs/compilers/CSharp/Compiler%20Breaking%20Changes%20-%20DotNet%2010.md).
The [`field`](../language-reference/keywords/field.md) contextual keyword is in C# 13 as a preview feature. The token `field` accesses the compiler synthesized backing field in a property accessor. It enables you to write an accessor body without declaring an explicit backing field in your type declaration. You can declare a body for one or both accessors for a field backed property.
28
+
29
+
The `field` feature is released as a preview feature. We want to learn from your experiences using it. There's a potential breaking change or confusion reading code in types that also include a field named `field`. You can use `@field` or `this.field` to disambiguate between the `field` keyword and the identifier.
If you try this feature and have feedback, add it to the [feature issue](https://github.com/dotnet/csharplang/issues/140) in the `csharplang` repository.
34
+
35
+
## Unbound generic types and nameof
36
+
37
+
Beginning with C# 14, the argument to `nameof` can be an unbound generic type. For example, `nameof(List<>)` evaluates to `List`. In earlier versions of C#, only closed generic types, such as `List<int>` had to be used to produce `List`.
38
+
39
+
<!-- Add link to What's new in .NET 10 once it's published -->
0 commit comments