// Static classes can only
// contain static members!
static class TimeUtilClass
{
public static void PrintTime()
{ Console.WriteLine(DateTime.Now.ToShortTimeString()); }
public static void PrintDate()
{ Console.WriteLine(DateTime.Today.ToShortDateString()); }
}
Given that this class has been defined with the static keyword, we cannot create an instance
of TimeUtilClass using the new keyword:
static void Main(string[] args)
{
Console.WriteLine("***** Fun with Static Data *****\n");
TimeUtilClass.PrintDate();
Do'stlaringiz bilan baham: |