I have a class, the stub of which is shown below. Code analysis gripes if I don’t remove the public constructor. But I’m curious why this is necessary on a sealed class? The particular class shown below only contains static methods. Why would it be good practice to include a private constructor just to remove the public one?
public sealed class ParseFile
{
/// <summary>
/// Remove the public constructor to satisfy CA1053.
/// </summary>
private ParseFile()
{
}
}
You’re not getting this warning because the class is sealed, but because it is (effectively) a static class.
A public constructor implies that the class has instance methods – classes that don’t shouldn’t advertise otherwise.