Tuesday 13 March 2012

Static Class in C#


//Demonstrate static Class with dateTime
using System;

static class TimeUtilClass
{
//To Print Only Time
public static void PrintTime()
{
Console.WriteLine(DateTime.Now.ToString("t"));
}

//To Print Only Date
public static void PrintDate()
{
Console.WriteLine(DateTime.Now.ToString("d"));
}

//To Print both Date and Time
public static void PrintDateTime()
{
Console.WriteLine(DateTime.Now.ToString());
}
}

class Program
{
static void Main()
{
TimeUtilClass.PrintTime();
TimeUtilClass.PrintDate();
TimeUtilClass.PrintDateTime();
}
}

No comments:

Post a Comment