- 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.
Courtesy: wikipedia
Check given year is leap year or not in C# – Complete Code
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public object IsLeapYear(int c_Year) { object functionReturnValue = null; if ((c_Year % 4 == 0) & ((c_Year % 100 != 0) | (c_Year % 400 == 0))) { functionReturnValue = true; } else { functionReturnValue = false; } return functionReturnValue; } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { int lp; lp = Convert.ToInt32(textBox1.Text ); MessageBox.Show(IsLeapYear(lp).ToString ()); } } } |

How to check given year is leap year or not in C# – enter year

How to check given year is leap year or not in C# – result shown
How to check given year is leap year or not in C#






