// The year (1 through 9999). // The month (1 through 12). static int CountSundays(int year, int month) { var firstDay = new DateTime(year,month , 1); var day29 = firstDay.AddDays(28); var day30 = firstDay.AddDays(29); var day31 = firstDay.AddDays(30); if ((day29.Month == month && day29.DayOfWeek == DayOfWeek.Sunday) || (day30.Month == month && day30.DayOfWeek == DayOfWeek.Sunday) || (day31.Month == month && day31.DayOfWeek == DayOfWeek.Sunday)) { return 5; } else { return 4; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)