C#10 introduced the ability to declare and use parameterless struct constructors, which means new Struct() and default(Struct) can be different. Consider the following code sample,
using System;
X.L(); // 12
X.K(); // 0
internal struct X
{
public int I;
public X()
{
I = 12;
}
public static void L()
{
Console.WriteLine(new X().I);
}
public static void K()
{
Console.WriteLine(default(X).I);
}
}
I believe that SA1129 "A value type was constructed using the syntax new T()." should not be removed, rather, it should check whether the struct defines a parameterless constructor before raising any warnings
C#10 introduced the ability to declare and use parameterless struct constructors, which means
new Struct()
anddefault(Struct)
can be different. Consider the following code sample,I believe that SA1129 "A value type was constructed using the syntax
new T()
." should not be removed, rather, it should check whether the struct defines a parameterless constructor before raising any warnings