- 
                Notifications
    You must be signed in to change notification settings 
- Fork 6.1k
create "what's new in C# 7.3" #5448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
        
          
                docs/csharp/whats-new/csharp-7-3.md
              
                Outdated
          
        
      |  | ||
| - You can test `==` and `!=` with tuple types. | ||
| - You can use expression variables in more locations. | ||
| - You may attach attributes to the backing field of auto implemented properties. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: auto-implemented
        
          
                docs/csharp/whats-new/csharp-7-3.md
              
                Outdated
          
        
      | - You can use expression variables in more locations. | ||
| - You may attach attributes to the backing field of auto implemented properties. | ||
| - Method resolution when arguments differ by `in` has been improved. | ||
| - Overload resolution new has fewer ambiguous cases. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: new -> now
        
          
                docs/csharp/whats-new/csharp-7-3.md
              
                Outdated
          
        
      |  | ||
| The new compiler options are: | ||
|  | ||
| - `deterministic` to ensure that subsequent compilations of the same source generate the same binary output. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised. "deterministic" is not a new option. It was there for a while.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we got behind. I can move it to the correct version. Do you know when it was first added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-deterministic was added in C# 6.0.
        
          
                docs/csharp/whats-new/csharp-7-3.md
              
                Outdated
          
        
      | --- | ||
| # What's new in C# 7.3 | ||
|  | ||
| 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 compilers were added in this release. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the last sentence: ...new compilers... -> ...new compiler options...
| - You can reassign `ref` local variables. | ||
| - You can use initializers on `stackalloc` arrays. | ||
| - You can use `fixed` statements with any type that supports a pattern. | ||
| - You can use additional generic constraints. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That one is on the border :). @BillWagner what made you put this in this theme and not in the theme of the enhancements to the existing features?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could go in either section. I put it here because of the unmanaged constraint. That enables some more perf oriented generic programming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I see, thank you for the reply.
        
          
                docs/csharp/whats-new/csharp-7-3.md
              
                Outdated
          
        
      | - You can use expression variables in more locations. | ||
| - You may attach attributes to the backing field of auto implemented properties. | ||
| - Method resolution when arguments differ by `in` has been improved. | ||
| - Overload resolution new has fewer ambiguous cases. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overload resolution new... -> New overload resolution...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"overload resolution now..."
        
          
                docs/csharp/whats-new/csharp-7-3.md
              
                Outdated
          
        
      |  | ||
| - `deterministic` to ensure that subsequent compilations of the same source generate the same binary output. | ||
| - `publicsign` to enable OSS signing of assemblies. | ||
| - `pathmap` to provide a mapping for source directories. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be dashes in front of each compiler option?
        
          
                docs/csharp/whats-new/csharp-7-3.md
              
                Outdated
          
        
      |  | ||
| ### Tuples support `==` and `!=` | ||
|  | ||
| The C# tuple types now support `==` and `!=`. You can learn more about the rules in the article on [tuples](../tuples.md). | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider to give the link to the section in that article: ../tuples.md#equality-and-tuples
        
          
                docs/csharp/whats-new/csharp-7-3.md
              
                Outdated
          
        
      |  | ||
| By default, every compilation 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. | ||
|  | ||
| For more information, see the [deterministic compiler option](../language-reference/compiler-options/deterministic-compiler-option.md) article. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: As far as I noticed, dashes are also used in the link texts throughout the docs.
        
          
                docs/csharp/whats-new/csharp-7-3.md
              
                Outdated
          
        
      |  | ||
| 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. | ||
|  | ||
| For more information, see the [publicsign compiler option](../language-reference/compiler-options/publicsign-compiler-option.md) article. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: dash in the link text
        
          
                docs/csharp/whats-new/csharp-7-3.md
              
                Outdated
          
        
      |  | ||
| 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>. | ||
|  | ||
| For more information, see the [pathmap compiler option](../language-reference/compiler-options/pathmap-compile-option.md) article. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: dash in the link text
        
          
                docs/csharp/whats-new/index.md
              
                Outdated
          
        
      | * [C# 7.1](csharp-7-1.md): | ||
| - 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). | ||
|  | ||
| - 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). | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first sentence should be: This page describes the features added in C# 7.1.
        
          
                docs/csharp/whats-new/index.md
              
                Outdated
          
        
      | * [C# 7.2](csharp-7-2.md): | ||
| - 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). | ||
|  | ||
| - 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). | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first sentence should be: This page describes the features added in C# 7.2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM Thanks!
| LGTM as well. Perhaps you could add a couple of enhancements: 
 | 
| OTOH, 
 Is this real? I've tested it with 7.2 and it works:  | 
| 
 I like this idea. I added it. 
 If want to keep this article reasonably short. The articles linked at the end of that section have samples of both Enum and Delegate, in addition to unmanaged. | 
| 
 Yes, and I added a note that this is a bug fix, and the new resolution applies even if C# 7.2 is selected as the language version. | 
        
          
                docs/csharp/whats-new/index.md
              
                Outdated
          
        
      | > 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. | ||
| * [C# 7.3](csharp-7-3.md): | ||
| - 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 Preview](../../core/whats-new/index.md). | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2.1.300 RC1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great @BillWagner. Left a couple of comments.
        
          
                docs/csharp/whats-new/csharp-7-3.md
              
                Outdated
          
        
      |  | ||
| 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. | ||
|  | ||
| You can learn more in the articles on [`where` generic constraints](../language-reference/keywords/where-generic-type-constraints.md) and the article covering [constraints on type parameters](../programming-guide/generics/constraints-on-type-parameters.md). | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are a few broken links warnings like this one in the build report
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed this one. The others rely on #5408
|  | ||
| You can learn more in the article on [`ref` returns and `ref` locals](../programming-guide/classes-and-structs/ref-returns.md). | ||
|  | ||
| ### `stackalloc` arrays support initializers | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I find it weird how the heading gets rendered when we use inline code. Wondering if it would be worth to ask them not to format inline code in headings while we still lock the word for Loc. Same applies to links.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm torn. I hate not styling them, because otherwise the first word should be caps. And the loc issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep the styling. My thought process was more related to UX changes. Like, should we work with @adkinn and co. to come up with some rules for when inline code should not be formatted like in headings and links?
        
          
                docs/csharp/whats-new/csharp-7-3.md
              
                Outdated
          
        
      |  | ||
| 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. | ||
|  | ||
| 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. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove comma from last sentence
        
          
                docs/csharp/whats-new/csharp-7-3.md
              
                Outdated
          
        
      |  | ||
| ### pathmap | ||
|  | ||
| 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>. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inline code pathmap?
        
          
                docs/csharp/whats-new/csharp-7-3.md
              
                Outdated
          
        
      | static void M(in S arg); | ||
| ``` | ||
|  | ||
| Now, the by value (first in the preceding example) overload is better than the by readonly reference version. To specify the by readonly reference version is called, you must include the `in` modifier when calling the method. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the first part of the last sentence is a bit hard to parse. Maybe if you change to something like "To call the by readonly reference version"?
        
          
                docs/csharp/whats-new/csharp-7-3.md
              
                Outdated
          
        
      |  | ||
| ```csharp | ||
| var arr = new int[3] {1, 2, 3}; | ||
| var arr2 = new int[] { 1, 2, 3}; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit remove extra space
        
          
                docs/csharp/whats-new/csharp-7-3.md
              
                Outdated
          
        
      |  | ||
| ```csharp | ||
| int* pArr = stackalloc int[3] {1, 2, 3}; | ||
| int* pArr2 = stackalloc int[] { 1, 2, 3}; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit remove extra space
        
          
                docs/csharp/whats-new/csharp-7-3.md
              
                Outdated
          
        
      |  | ||
| ### Extend expression variables in initializers | ||
|  | ||
| The syntax added in C# 7.0 to permit 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: | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace permit with allow? inline code out?
        
          
                docs/csharp/whats-new/csharp-7-3.md
              
                Outdated
          
        
      |  | ||
| ## New compiler options | ||
|  | ||
| New compiler options support new build and DevOps scenarios for C# programs | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing punctuation
        
          
                docs/csharp/whats-new/csharp-7-3.md
              
                Outdated
          
        
      |  | ||
| The new compiler options are: | ||
|  | ||
| - `-publicsign` to enable OSS signing of assemblies. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spell out OSS on first usage
        
          
                docs/csharp/whats-new/csharp-7-3.md
              
                Outdated
          
        
      | ### Tuples support `==` and `!=` | ||
|  | ||
| The C# tuple types now support `==` and `!=`. You can learn more about the rules in the article on [tuples](../tuples.md#equality-and-tuples). | ||
| 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#equality-and-tuples). | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the sentence should end with the link to the article itself, not the section:
...in the article on [tuples](../tuples.md)
        
          
                docs/csharp/whats-new/csharp-7-3.md
              
                Outdated
          
        
      | ### Extend expression variables in initializers | ||
|  | ||
| The syntax added in C# 7.0 to permit 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: | ||
| The syntax added in C# 7.0 to aloow `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: | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: aloow -> allow
        
          
                docs/csharp/whats-new/csharp-7-3.md
              
                Outdated
          
        
      | ### pathmap | ||
|  | ||
| 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>. | ||
| 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>. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add dash to the second mention of -pathmap
| closing and reopening to start a new build. | 
        
          
                docs/csharp/whats-new/csharp-7-3.md
              
                Outdated
          
        
      | } | ||
| ``` | ||
|  | ||
| The variable `p` doesn't need to be pinned. Note that you still need an `unsafe` context. In earlier versions of C#, you need to declare a second fixed pointer: | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's inaccurate to say that p doesn't need to be pinned. p is just an int, it can't be pinned and the following example does not pin p.
| public void M() | ||
| { | ||
| int p = s.myFixedField[5]; | ||
| } | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the following text says, this code has be in an unsafe context, so I think this example should include unsafe somewhere (probably on the method).
|  | ||
| ```csharp | ||
| ref VeryLargeStruct reflocal = ref veryLargeStruct; // initialization | ||
| refLocal = ref anotherVeryLargeStruct; // reassigned, refLocal refers to different storage. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: first line uses reflocal (with lowecase l), second line refLocal (with capital L).
| There are some build warnings here, @BillWagner. I'll take a look at the rest now. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. @svick had some new comments you might wanna check and you still have one instance of OSS which is not spelled out. You can use the acronym after you show what it means once.
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
469998f    to
    e5e4ce1      
    Compare
  
    compile => compiler.
| Now, `ref` locals may be reassigned to refer to different instances after being initialized. The following code now compiles: | ||
|  | ||
| ```csharp | ||
| ref VeryLargeStruct refLocal = ref veryLargeStruct; // initialization | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is one more form of ref local re-assignment: foreach ref. It was missing from the spec, but it is implemented and shipped.
using System;
class E
{
    public class Enumerator
    {
        public ref int Current => throw new NotImplementedException();
        public bool MoveNext() => throw new NotImplementedException();
    }
    public Enumerator GetEnumerator() => new Enumerator();
}
class C
{
    void M()
    {
        foreach (ref int x in new E())
        {
        }
    }
}[I'd given a bad example. Updated]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jcouv that means we can make such shoot-in-the-leg things now:
var _array = new byte[5];
new Random(42).NextBytes(_array);
Span<byte> span = _array;
foreach (ref byte element in span)
{
    element = 4;
    Console.WriteLine(element);
}
Console.WriteLine(string.Join(" ", _array));
Console.ReadLine();That outputs only 4s. Wow.
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
Summary
Describe your changes here.
Fixes #Issue_Number (if available)