# VBForums CodeBank > CodeBank - C# >  LYL Leep Year Lister.

## BenJones

Hi this is a small little console project to list leap years between two different dates.
Very simple to use enter a starting date and an ending date. Hope you find it us full.


csharp Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 namespace LYL
{
    class Program
    {
        private static bool IsLeapYear(int year)
        {
            //Check for leap year.
            if ((year % 4 == 0 && !(year % 100 == 0 && !(year % 400 == 0))))
                return true;
            return false;
        }
         static void Main(string[] args)
        {
            int _startY = 0;
            int _endY = 0;
            int I = 0;
             Console.WriteLine("+------------------+");
            Console.WriteLine("+ Leap Year Lister +");
            Console.WriteLine("+ By Ben           +");
            Console.WriteLine("+------------------+");
             try
            {
                Console.Write("Enter starting year: ");
                _startY = int.Parse(Console.ReadLine());
                Console.Write("Enter ending year: ");
                _endY = int.Parse(Console.ReadLine());
            }
            catch
            {
                return;
            }
             //Print out years
            for (I = _startY; I < _endY + 1; I++)
            {
                //Test for leap year.
                if (IsLeapYear(I))
                {
                    //Was leap year.
                    Console.WriteLine(I + " is a leap year");
                }
                else
                {
                    //Was not a leap year
                    Console.WriteLine(I + " was not a leap year.");
                }
            }
        }
    }
}

----------


## kfcSmitty

I know this isn't code it better, but instead of using a try/catch to check whether a user has input a valid integer, you should really be using .TryParse. If, at any time, you can handle an error (and actually do something about it) without using an exception, you should.

----------

