Prior to .NET 2.0, the only way to prevent the creation of a class type was to either redefine the
default constructor as private or mark the class as an abstract type using the C# abstract keyword
(full details regarding abstract types are in Chapter 6):
class TimeUtilClass
{
// Redefine the default ctor as private
// to prevent creation.
private
TimeUtilClass (){}
public static void PrintTime()
{ Console.WriteLine(DateTime.Now.ToShortTimeString()); }
public static void PrintDate()
{ Console.WriteLine(DateTime.Today.ToShortDateString()); }
}
Do'stlaringiz bilan baham: