Skip to content

Commit 7534a56

Browse files
authored
create "what's new in C# 7.3" (#5448)
* create "what's new in C# 7.3" Fixes #5289 This PR adds the overview to "What's new in C# 7.3". I updated the wording in the TOC to remove the repeated "What's new" phrasing. /cc @jcouv @MadsTorgersen /cc @Welchen This PR relies on new files added in PR #5408 * respond to feedback * respond to feedback * more feedback * respond to feedback. * fix a build error compile => compiler.
1 parent 1aa1f3c commit 7534a56

File tree

4 files changed

+248
-44
lines changed

4 files changed

+248
-44
lines changed

docs/csharp/whats-new/csharp-6.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ productivity for developers. Features in this release include:
3434
- Collection initializers can rely on accessible extension methods, in addition to member methods.
3535
* [Improved overload resolution](#improved-overload-resolution):
3636
- Some constructs that previously generated ambiguous method calls now resolve correctly.
37+
* [`deterministic` compiler option](#deterministic-compiler-output):
38+
- The deterministic compiler option ensures that subsequent compilations of the same source generate the same binary output.
3739

3840
The overall effect of these features is that you write more concise code
3941
that is also more readable. The syntax contains less ceremony for many
@@ -570,3 +572,12 @@ a lambda expression as an argument:
570572

571573
The C# 6 compiler correctly determines that `Task.Run(Func<Task>())` is
572574
a better choice.
575+
576+
### Deterministic compiler output
577+
578+
The `-deterministic` option instructs the compiler to produce a byte-for-byte identical output assembly for successive compilations of the same source files.
579+
580+
By default, every compilation produces unique output on each compilation. The compiler adds a timestamp, and a GUID generated from random numbers. You use this option if you want to compare the byte-for-byte output to ensure consistency across builds.
581+
582+
For more information, see the [-deterministic compiler option](../language-reference/compiler-options/deterministic-compiler-option.md) article.
583+
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
---
2+
title: What's new in C# 7.3
3+
description: An overview of new features in C# 7.3
4+
ms.date: 05/16/2018
5+
---
6+
# What's new in C# 7.3
7+
8+
There are two main themes to the C# 7.3 release. One theme provides features that enable safe code to be as performant as unsafe code. The second theme provides incremental improvements to existing features. In addition, new compiler options were added in this release.
9+
10+
The following new features support the theme of better performance for safe code:
11+
12+
- You can access fixed fields without pinning.
13+
- You can reassign `ref` local variables.
14+
- You can use initializers on `stackalloc` arrays.
15+
- You can use `fixed` statements with any type that supports a pattern.
16+
- You can use additional generic constraints.
17+
18+
The following enhancements were made to existing features:
19+
20+
- You can test `==` and `!=` with tuple types.
21+
- You can use expression variables in more locations.
22+
- You may attach attributes to the backing field of auto-implemented properties.
23+
- Method resolution when arguments differ by `in` has been improved.
24+
- Overload resolution now has fewer ambiguous cases.
25+
26+
The new compiler options are:
27+
28+
- `-publicsign` to enable Open Source Software (OSS) signing of assemblies.
29+
- `-pathmap` to provide a mapping for source directories.
30+
31+
The remainder of this article provides details and links to learn more about each of the improvements.
32+
33+
## Enabling more performant safe code
34+
35+
You should be able to write C# code safely that performs as well as unsafe code. Safe code avoids classes of errors, such as buffer overruns, stray pointers, and other memory access errors. These new features expand the capabilities of verifiable safe code. Strive to write more of your code using safe constructs. These features make that easier.
36+
37+
### Indexing `fixed` fields does not require pinning
38+
39+
Consider this struct:
40+
41+
```csharp
42+
unsafe struct S
43+
{
44+
public fixed int myFixedField[10];
45+
}
46+
```
47+
48+
In earlier versions of C#, you needed to pin a variable to access one of the integers that are part of `myFixedField`. Now, the following code compiles in a safe context:
49+
50+
```csharp
51+
class C
52+
{
53+
static S s = new S();
54+
55+
unsafe public void M()
56+
{
57+
int p = s.myFixedField[5];
58+
}
59+
}
60+
```
61+
62+
The variable `p` accesses one element in `myFixedField`. You don't need to declare a separate `int*` variable. Note that you still need an `unsafe` context. In earlier versions of C#, you need to declare a second fixed pointer:
63+
64+
```csharp
65+
class C
66+
{
67+
static S s = new S();
68+
69+
public void M()
70+
{
71+
fixed (int* ptr = s.myFixedField)
72+
{
73+
int p = ptr[5];
74+
}
75+
}
76+
}
77+
```
78+
79+
Fore more information, see the article on the [`fixed` statement](../language-reference/keywords/fixed-statement.md).
80+
81+
### `ref` local variables may be reassigned
82+
83+
Now, `ref` locals may be reassigned to refer to different instances after being initialized. The following code now compiles:
84+
85+
```csharp
86+
ref VeryLargeStruct refLocal = ref veryLargeStruct; // initialization
87+
refLocal = ref anotherVeryLargeStruct; // reassigned, refLocal refers to different storage.
88+
```
89+
90+
For more information, see the article on [`ref` returns and `ref` locals](../programming-guide/classes-and-structs/ref-returns.md).
91+
92+
### `stackalloc` arrays support initializers
93+
94+
You've been able to specify the values for elements in an array when you initialize it:
95+
96+
```csharp
97+
var arr = new int[3] {1, 2, 3};
98+
var arr2 = new int[] {1, 2, 3};
99+
```
100+
101+
Now, that same syntax can be applied to arrays that are declared with `stackalloc`:
102+
103+
```csharp
104+
int* pArr = stackalloc int[3] {1, 2, 3};
105+
int* pArr2 = stackalloc int[] {1, 2, 3};
106+
Span<int> arr = stackalloc [] {1, 2, 3};
107+
```
108+
109+
For more information, see the [`stackalloc` statement](../language-reference/keywords/stackalloc.md) article in the language reference.
110+
111+
### More types support the `fixed` statement
112+
113+
The `fixed` statement supported a limited set of types. Starting with C# 7.3, any type that contains a `DangerousGetPinnableReference()` method that returns a `ref T` or `ref readonly T` may be `fixed`. Adding this feature means that `fixed` can be used with <xref:System.Span%601?displayProperty=nameWithType> and related types.
114+
115+
For more information, see the [`fixed` statement](../language-reference/keywords/fixed-statement.md) article in the language reference.
116+
117+
### Enhanced generic constraints
118+
119+
You can now specify the type <xref:System.Enum?displayProperty=nameWithType> or <xref:System.Delegate?displayProperty=nameWithType> as base class constraints for a type parameter.
120+
121+
You can also use the new `unmanaged` constraint, to specify that a type parameter must be an **unmanaged type**. An **unmanaged type** is a type that isn't a reference type and doesn't contain any reference type at any level of nesting.
122+
123+
For more information, see the articles on [`where` generic constraints](../language-reference/keywords/where-generic-type-constraint.md) and [constraints on type parameters](../programming-guide/generics/constraints-on-type-parameters.md).
124+
125+
## Make existing features better
126+
127+
The second theme provides improvements to features in the language. These features improve productivity when writing C#.
128+
129+
### Tuples support `==` and `!=`
130+
131+
The C# tuple types now support `==` and `!=`. Fore more information, see the section covering [equality](../tuples.md#equality-and-tuples) in the article on [tuples](../tuples.md).
132+
133+
### Attach attributes to the backing fields for auto-implemented properties
134+
135+
This syntax is now supported:
136+
137+
```csharp
138+
[field: SomeThingAboutFieldAttribute]
139+
public int SomeProperty { get; set; }
140+
```
141+
142+
The attribute `SomeThingAboutFieldAttribute` is applied to the compiler generated backing field for `SomeProperty`. For more information, see [attributes](../programming-guide/concepts/attributes/index.md) in the C# programming guide.
143+
144+
### `in` method overload resolution tiebreaker
145+
146+
When the `in` argument modifier was added, these two methods would cause an ambiguity:
147+
148+
```csharp
149+
static void M(S arg);
150+
static void M(in S arg);
151+
```
152+
153+
Now, the by value (first in the preceding example) overload is better than the by readonly reference version. To call the version with the readonly reference argument, you must include the `in` modifier when calling the method.
154+
155+
> [!NOTE]
156+
> This was implemented as a bug fix. This no longer is ambiguous even with the language version set to "7.2".
157+
158+
For more information, see the article on the [`in` parameter modifier](../language-reference/keywords/in-parameter-modifier.md).
159+
160+
### Extend expression variables in initializers
161+
162+
The syntax added in C# 7.0 to allow `out` variable declarations has been extended to include field initializers, property initializers, constructor initializers, and query clauses. It enables code such as the following example:
163+
164+
```csharp
165+
public class B
166+
{
167+
public B(int i, out int j)
168+
{
169+
j = i;
170+
}
171+
}
172+
173+
public class D : B
174+
{
175+
public D(int i) : B(i, out var j)
176+
{
177+
Console.WriteLine($"The value of 'j' is {j}");
178+
}
179+
}
180+
```
181+
182+
### Improved overload candidates
183+
184+
In every release, the overload resolution rules get updated to address situations where ambiguous method invocations have an "obvious" choice. This release adds three new rules to help the compiler pick the obvious choice:
185+
186+
1. When a method group contains both instance and static members, the compiler discards the instance members if the method was invoked without an instance receiver or context. The compiler discards the static members if the method was invoked with an instance receiver. When there is no receiver, the compiler includes only static members in a static context, otherwise both static and instance members. When the receiver is ambiguously an instance or type, the compiler includes both. A static context, where an implicit `this` instance receiver cannot be used, includes the body of members where no `this` is defined, such as static members, as well as places where `this` cannot be used, such as field initializers and constructor-initializers.
187+
1. When a method group contains some generic methods whose type arguments do not satisfy their constraints, these members are removed from the candidate set.
188+
1. For a method group conversion, candidate methods whose return type doesn't match up with the delegate's return type are removed from the set.
189+
190+
You'll only notice this change because you'll find fewer compiler errors for ambiguous method overloads when you are sure which method is better.
191+
192+
## New compiler options
193+
194+
New compiler options support new build and DevOps scenarios for C# programs.
195+
196+
### Public or Open Source signing
197+
198+
The `-publicsign` compiler option instructs the compiler to sign the assembly using a public key. The assembly is marked as signed, but the signature is taken from the public key. This option enables you to build signed assemblies from open-source projects using a public key.
199+
200+
For more information, see the [-publicsign compiler option](../language-reference/compiler-options/publicsign-compiler-option.md) article.
201+
202+
### pathmap
203+
204+
The `-pathmap` compiler option instructs the compiler to replace source paths from the build environment with mapped source paths. The `-pathmap` option controls the source path written by the compiler to PDB files or for the <xref:System.Runtime.CompilerServices.CallerFilePathAttribute>.
205+
206+
For more information, see the [-pathmap compiler option](../language-reference/compiler-options/pathmap-compiler-option.md) article.

docs/csharp/whats-new/index.md

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,52 +12,38 @@ the C# language. The following links provide detailed information on the
1212
major features added in each release.
1313

1414
> [!IMPORTANT]
15-
> The C# language relies on types and methods in a *standard library* for some of the features. One example is exception processing. Every `throw` statement or expression is checked to ensure the object being thrown is derived from <xref:System.Exception>. Similarly, every `catch` is checked to ensure that the type being caught is derived from <xref:System.Exception>. Each version may add new requirements. To use the latest language features in older environments, you may need to install specific libraries. These dependencies are documented in the page for each specific version. You can learn more about the [relationships between language and library](relationships-between-language-and-library.md) for background on this dependency.
16-
15+
> The C# language relies on types and methods in a *standard library* for some of the features. One example is exception processing. Every `throw` statement or expression is checked to ensure the object being thrown is derived from <xref:System.Exception>. Similarly, every `catch` is checked to ensure that the type being caught is derived from <xref:System.Exception>. Each version may add new requirements. To use the latest language features in older environments, you may need to install specific libraries. These dependencies are documented in the page for each specific version. For more information, see the article on the [relationships between language and library](relationships-between-language-and-library.md) for background on this dependency.
1716
17+
* [C# 7.3](csharp-7-3.md):
18+
- This page describes the latest features in the C# language. C# 7.3 is currently available in [Visual Studio 2017 version 15.7](https://www.visualstudio.com/vs/whatsnew/), and in the [.NET Core 2.1 SDK 2.1.300 RC1](../../core/whats-new/index.md).
1819
* [C# 7.2](csharp-7-2.md):
19-
- This page describes the latest features in the C# language. C# 7.2 is currently available in [Visual Studio 2017 version 15.5](https://www.visualstudio.com/vs/whatsnew/), and in the [.NET Core 2.0 SDK](../../core/whats-new/index.md).
20-
20+
- This page describes the features added in the C# language. C# 7.2 is currently available in [Visual Studio 2017 version 15.5](https://www.visualstudio.com/vs/whatsnew/), and in the [.NET Core 2.0 SDK](../../core/whats-new/index.md).
2121
* [C# 7.1](csharp-7-1.md):
22-
- This page describes the features in C# 7.1. These features were added in [Visual Studio 2017 version 15.3](https://www.visualstudio.com/vs/whatsnew/), and in the [.NET Core 2.0 SDK](../../core/whats-new/index.md).
23-
22+
- This page describes the features added in C# 7.1. These features were added in [Visual Studio 2017 version 15.3](https://www.visualstudio.com/vs/whatsnew/), and in the [.NET Core 2.0 SDK](../../core/whats-new/index.md).
2423
* [C# 7.0](csharp-7.md):
25-
- This page describes the features added in C# 7.0. These features were added in [Visual Studio 2017](https://www.visualstudio.com/vs/whatsnew/) and [.NET Core 1.0](../../core/whats-new/index.md) and later
26-
24+
- This page describes the features added in C# 7.0. These features were added in [Visual Studio 2017](https://www.visualstudio.com/vs/whatsnew/) and [.NET Core 1.0](../../core/whats-new/index.md) and later
2725
* [C# 6](csharp-6.md):
28-
- This page describes the features that were added in C# 6. These features are available in Visual Studio 2015 for Windows developers, and on .NET Core 1.0 for developers exploring C# on macOS and Linux.
29-
30-
<!--* [C# Interactive](../interactive/index.md):
31-
- This page describes C# Interactive, an interactive Read Eval Print Loop (REPL) that you can use to explore the C# language. You can use it to write code interactively and see it execute immediately, without any compile or build step.
32-
-->
26+
- This page describes the features that were added in C# 6. These features are available in Visual Studio 2015 for Windows developers, and on .NET Core 1.0 for developers exploring C# on macOS and Linux.
3327
* [Cross Platform Support](../../core/index.md):
34-
- C#, through .NET Core support, runs on multiple platforms. If you are interested in trying C# on macOS, or on one of the many supported Linux distributions, learn more about .NET Core.
28+
- C#, through .NET Core support, runs on multiple platforms. If you are interested in trying C# on macOS, or on one of the many supported Linux distributions, learn more about .NET Core.
29+
* [.NET Compiler Platform SDK](../roslyn-sdk/index.md):
30+
- The .NET Compiler Platform SDK enables you to write code that performs static analysis on C# code. You can use these APIs to find potential errors, or bad practices, suggest fixes, and even implement those fixes.
3531

36-
<!--
37-
- [.NET Compiler Platform SDK](../roslyn/index.md):
38-
- The .NET Compiler Platform SDK enables you to write code that performs static analysis on C# code. You can use these APIs to find potential errors, or bad practices, suggest fixes, and even implement those fixes.
39-
-->
40-
4132
## Previous Versions
42-
The following lists key features that were introduced in previous versions of the C# language and Visual Studio .NET.
43-
44-
* Visual Studio .NET 2013:
45-
- This version of Visual Studio included bug fixes, performance improvements, and technology previews of .NET Compiler Platform ("Roslyn") which became the .NET Compiler Platform SDK<!--Link to ../roslyn/index.md-->.
46-
47-
* C# 5, Visual Studio .NET 2012:
48-
- `Async` / `await`, and [caller information](../programming-guide/concepts/caller-information.md) attributes.
49-
50-
* C# 4, Visual Studio .NET 2010:
51-
- `Dynamic`, [named arguments](../programming-guide/classes-and-structs/named-and-optional-arguments.md), optional parameters, and generic [covariance and contra variance](../programming-guide/concepts/covariance-contravariance/index.md).
52-
53-
* C# 3, Visual Studio .NET 2008:
54-
- Object and collection initializers, lambda expressions, extension methods, anonymous types, automatic properties, local `var` type inference, and [Language Integrated Query (LINQ)](../programming-guide/concepts/linq/index.md).
55-
56-
* C# 2, Visual Studio .NET 2005:
57-
- Anonymous methods, generics, nullable types, iterators/yield, `static` classes, and covariance and contra variance for delegates.
58-
59-
* C# 1.1, Visual Studio .NET 2003:
60-
- `#line` pragma and xml doc comments.
6133

62-
* C# 1, Visual Studio .NET 2002:
63-
- The first release of [C#](../csharp.md).
34+
The following lists key features that were introduced in previous versions of the C# language and Visual Studio .NET.
35+
36+
* Visual Studio .NET 2013:
37+
- This version of Visual Studio included bug fixes, performance improvements, and technology previews of .NET Compiler Platform ("Roslyn") which became the [.NET Compiler Platform SDK](../roslyn-sdk/index.md).
38+
* C# 5, Visual Studio .NET 2012:
39+
- `Async` / `await`, and [caller information](../programming-guide/concepts/caller-information.md) attributes.
40+
* C# 4, Visual Studio .NET 2010:
41+
- `Dynamic`, [named arguments](../programming-guide/classes-and-structs/named-and-optional-arguments.md), optional parameters, and generic [covariance and contra variance](../programming-guide/concepts/covariance-contravariance/index.md).
42+
* C# 3, Visual Studio .NET 2008:
43+
- Object and collection initializers, lambda expressions, extension methods, anonymous types, automatic properties, local `var` type inference, and [Language Integrated Query (LINQ)](../programming-guide/concepts/linq/index.md).
44+
* C# 2, Visual Studio .NET 2005:
45+
- Anonymous methods, generics, nullable types, iterators/yield, `static` classes, and covariance and contra variance for delegates.
46+
* C# 1.1, Visual Studio .NET 2003:
47+
- `#line` pragma and xml doc comments.
48+
* C# 1, Visual Studio .NET 2002:
49+
- The first release of [C#](../csharp.md).

docs/toc.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,11 @@
215215
<!-- The "What's New" section is short, and one level
216216
deep, so leave it in the main TOC -->
217217
## [What's new in C#](csharp/whats-new/index.md)
218-
### [What's new in C# 7.2](csharp/whats-new/csharp-7-2.md)
219-
### [What's new in C# 7.1](csharp/whats-new/csharp-7-1.md)
220-
### [What's new in C# 7.0](csharp/whats-new/csharp-7.md)
221-
### [What's new in C# 6](csharp/whats-new/csharp-6.md)
218+
### [C# 7.3](csharp/whats-new/csharp-7-3.md)
219+
### [C# 7.2](csharp/whats-new/csharp-7-2.md)
220+
### [C# 7.1](csharp/whats-new/csharp-7-1.md)
221+
### [C# 7.0](csharp/whats-new/csharp-7.md)
222+
### [C# 6](csharp/whats-new/csharp-6.md)
222223
### [C# Version History](csharp/whats-new/csharp-version-history.md)
223224
### [Relationships between language and framework](csharp/whats-new/relationships-between-language-and-library.md)
224225
<!-- End What's New -->

0 commit comments

Comments
 (0)