- This topic shows how to check given year is leap year or not in C#
- We enter year in a TextBox and the result will shows in a message box when we click the button.
What is Leap Year?
- A leap year (or intercalary or bissextile year) is a year containing one additional day (or, in the case of lunisolar calendars, a month) in order to keep the calendar year synchronized with the astronomical or seasonal year. Because seasons and astronomical events do not repeat in a whole number of days, a calendar that had the same number of days in each year would, over time, drift with respect to the event it was supposed to track. By occasionally inserting (or intercalating) an additional day or month into the year, the drift can be corrected. A year that is not a leap year is called a common year.
- For example, in the Gregorian calendar (a common solar calendar), February in a leap year has 29 days instead of the usual 28, so the year lasts 366 days instead of the usual 365. Similarly, in the Hebrew calendar (a lunisolar calendar), Adar Aleph, a 13th lunar month is added seven times every 19 years to the twelve lunar months in its common years to keep its calendar year from drifting through the seasons too rapidly.
- The term leap year gets its name from the fact that while a fixed date in the Gregorian calendar normally advances one day of the week from one year to the next, in a leap year it will advance two days due to the year’s extra day (thus “leaping over” one of the days in the week). For example, Christmas Day fell on Saturday in 2004, Sunday in 2005, Monday in 2006 and Tuesday in 2007 but then “leapt” over Wednesday to fall on a Thursday in 2008.
Check given year is leap year or not in C# – Complete Code
public partial class Form1 : Form
public object IsLeapYear(int c_Year)
object functionReturnValue = null;
if ((c_Year % 4 == 0) & ((c_Year % 100 != 0) | (c_Year % 400 == 0)))
functionReturnValue = true;
functionReturnValue = false;
private void Form1_Load(object sender, EventArgs e)
private void button1_Click(object sender, EventArgs e)
lp = Convert.ToInt32(textBox1.Text );
How to check given year is leap year or not in C#