When using the C# 9 new() syntax ( Target-typed new) with private constructors, Sonarcloud reports one of the following issues:
Code Smell: Remove the unused private constructor Foo
public class Foo
{
private Foo()
{
}
public static Foo Create()
{
return new();
}
}
Bug: This class can’t be instantiated; make its constructor ‘public’.
public class Foo
{
public static readonly Foo Instance = new();
private Foo()
{
}
}