public static void Main()
var date1=new Period("Jan",2014);
Console.WriteLine("First Date is {0}",date1);
Console.WriteLine("Second Date is {0}",date2);
Console.WriteLine("First Date is the same as second date value");
Console.WriteLine("First Date is less than the second date value");
Console.WriteLine("First Date is greater than the second date value");
public class Period:IComparable
public Period(string Month,int Year)
public int CompareTo(object obj)
Period period = obj as Period;
if(this.Month=="Present" && period.Month=="Present")
else if(period.Month=="Present")
else if(this.Month=="Present")
if(!DateTime.TryParse(string.Format("01 {0} {1}",Month,Year),out date))
throw new ArgumentException("Instance is not a valid Period!");
if(!DateTime.TryParse(string.Format("01 {0} {1}",period.Month,period.Year),out periodDate))
throw new ArgumentException("Object is not a valid Period!");
return date.Date.CompareTo(periodDate.Date);
throw new ArgumentException("Object is not a Period");
public override int GetHashCode()
if(!DateTime.TryParse(string.Format("01 {0} {1}",Month,Year),out date))
throw new ArgumentException("Instance is not a valid Period!");
return date.GetHashCode();
public override bool Equals(object obj)
return this.CompareTo(obj)==0;
public static bool operator==(Period left, Period right)
return left.Equals(right);
public static bool operator!=(Period left, Period right)
public static bool operator<(Period left, Period right)
return left.CompareTo(right)<0;
public static bool operator>(Period left, Period right)
return left.CompareTo(right)>0;
public override string ToString()
if(string.IsNullOrWhiteSpace(Month))
else if(Month=="Present")
return string.Format("{0} {1}",Month,Year);
public string Month{get; set;}
public int Year{get; set;}