Version Used:
Compiler version: '3.10.0-4.21269.26 (0298477). Language version 9.0.
Steps to Reproduce:
int? x = new int?(); // sets x to null
int? y = new(); // sets y to 0
System.Console.WriteLine($"x = {x}");
System.Console.WriteLine($"y = {y}");
Expected Behavior:
In my opinion, the least surprising option would be to have the second line should behave the same way as the first, i.e. y should be initialized to null in the above program, although the C# 9 spec implies that the current behavior is correct.
If these cases are intended to produce different results, then the IDE0090 suggestion should not be shown.
Actual Behavior:
The first line (setting x) receives a suggestion "IDE0090: 'new' expression can be simplified" - applying this suggestion changes the behavior of the program as x ends up being initialized to 0.
Output:
Version Used:
Compiler version: '3.10.0-4.21269.26 (0298477). Language version 9.0.
Steps to Reproduce:
Expected Behavior:
In my opinion, the least surprising option would be to have the second line should behave the same way as the first, i.e.yshould be initialized tonullin the above program, although the C# 9 spec implies that the current behavior is correct.If these cases are intended to produce different results, then the IDE0090 suggestion should not be shown.
Actual Behavior:
The first line (setting
x) receives a suggestion "IDE0090: 'new' expression can be simplified" - applying this suggestion changes the behavior of the program asxends up being initialized to 0.Output: