Collection base on year Can someone please review the code and suggest any improvements / changes? Note that this method works but wanted to see if there is a better way to reset the currentYearMeetingCount to -1. I just want to print the data if there is data for that year and for the past 3 years.

 class Program
    {
        static void Main(string[] args)
        {
            List&lt;Meeting&gt; Meeting = new List&lt;Meeting&gt;();
            Meeting.Add(new Meeting() { Name="a", Year = 2019 });
            Meeting.Add(new Meeting() { Name="b", Year = 2019 });
            Meeting.Add(new Meeting() { Name = "c", Year = 2019 });
            Meeting.Add(new Meeting() { Name = "d", Year = 2018 });
            Meeting.Add(new Meeting() { Name = "e", Year = 2018 });
            Meeting.Add(new Meeting() { Name = "f", Year = 2017 });
            Meeting.Add(new Meeting() { Name = "g", Year = 2016 });
            Meeting.Add(new Meeting() { Name = "h", Year = 2015 });
            //string Ids = peopleList.Select(x =&gt; x.ID);


            int totalYearCount = 3;
            DateTime aDate = DateTime.Now;

            int currentYearMeetingCount = Meeting.Where(x =&gt; x.Year == aDate.Year).Count();

            if (currentYearMeetingCount == 0)
            {
                aDate = DateTime.Now.AddYears(-1);

            }

            foreach (var year in Enumerable.Range(aDate.Year - totalYearCount + 1, totalYearCount).Reverse())
            {

                var meetingList = Meeting.Where(x =&gt; x.Year == year);
                foreach (var meeting in meetingList)
                {
                    Console.WriteLine("{0}-{1}", meeting.Name, meeting.Year);
                }

            }
        }



        class Meeting
        {
            public int Year { get; set; }
            public string Name { get; set; }
        }
    }
There is no need for this 

DateTime aDate = DateTime.Now;

int currentYearMeetingCount = Meeting.Where(x =&gt; x.Year == aDate.Year).Count();

if (currentYearMeetingCount == 0)
{
    aDate = DateTime.Now.AddYears(-1);

}


if the collection has no data for the current year, it'll only get the past 3 years if any.  so, you can do this directly : 

var totalYearCount = 3;
var maxYear = DateTime.Now.Year;
var minYear = maxYear - totalYearCount;

var result = Meeting.Where(x=&gt; x.Year &gt;= minYear &amp;&amp; x.Year &lt;= maxYear).ToList();

if(result.Count == 0) 
{
    // no data, do something 
}

foreach(var meeting in result)
{
    Console.WriteLine($"{meeting.Name}-{meeting.Year}");
}


this will output 2017-2019 records. However, if your logic has a special case, let's say if there is no records for current year, then start with the last year instead so the output will be from 2016 to 2019. If this is the case, then instead of depending on DateTime.Now.Year you can get the max year from the collection, and subtract the past x years from it. Something like this : 

var totalYearCount = 3;
var maxYear = Meeting.Max(x=&gt; x.Year);
var minYear = maxYear - totalYearCount;
var result = Meeting.Where(x=&gt; x.Year &gt;= minYear &amp;&amp; x.Year &lt;= maxYear).ToList();

if(result.Count == 0) 
{
    // no data, do something 
}

foreach(var meeting in result)
{
    Console.WriteLine($"{meeting.Name}-{meeting.Year}");
}


this will output 2016-2019 records, and if there is any records for the current year (say 2020), then it'll output 2017-2020.