Thursday, December 23, 2010

Check if Leap Year

Below is a custom code i have been working to check if a year is considered as leap year.
Code:
  protected bool CheckLeap(int year)  
  {  
     if((year%4==0&&year%100!=0)||year%400==0)  
     {  
       return true;  
     }  
     return false;  
  }  

However, as i checked the DateTime class methods in MSDN, i found a handy tool to do the same functionality.
Code:
DateTime.IsLeapYear(int year);  

Cheers!

0 comments:

Post a Comment