Sealed class - why remove a public constructor?

I have a class whose stub is shown below. Code analysis is exciting if I do not remove the public constructor. But I'm curious why this is necessary in a sealed class? The class below contains only static methods. Why would it be good practice to include a private constructor to remove the public one?

    public sealed class ParseFile
    {
        /// <summary>
        /// Remove the public constructor to satisfy CA1053.
        /// </summary>
        private ParseFile()
        {
        }
    }
+5
source share
5 answers

You will not receive this warning because the class is sealed, but because it is (effectively) a static class.

An open constructor implies that a class has instance methods — classes that should not advertise otherwise.

+11
source

, .

public static class ParseFile 
{ 
} 
+14

- , Static. , . , , .

+3

A class with all the static method never needs a constructor, because it is not created using a new keyword. Therefore, you do not need a public constructor.

+2
source

All Articles