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() { } }
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.
, .
public static class ParseFile { }
, , ?, System.Math. , ( ) .
, , ?
, System.Math. , ( ) .
EDIT: source http://social.msdn.microsoft.com/Forums/en-US/vstscode/thread/8addbc70-f720-4d0b-85ce-2bdf52e32f77
, , . .
- , Static. , . , , .
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.