namespace ConsoleAppWeekday
public static void Main(string[] args)
if (args == null || args.Length <= 1 || args[0].ToLower() == "--help")
Console.WriteLine(args[0]);
Console.WriteLine(args[1]);
int year = int.Parse(args[0]);
int day = int.Parse(args[1]);
int numberOfDays = Weekday.WeekdaysInFirstOfTheMonth(year, day);
string weekday = Weekday.GetWeekday(day);
Console.WriteLine("In the year {0}, {1} fell on the first of the month {2} times.", year, day, numberOfDays);
catch(FormatException ex)
Console.WriteLine("Wrong type of arguments...");
Console.WriteLine("Unexpected error...");
private static void ShowHelp()
Console.WriteLine("USAGE: program YYYY Weekday");
public static class Weekday
public static int GetWeekday(int d, int m, int y)
int[] t = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
return (y + y / 4 - y / 100 + y / 400 + t[m - 1] + d) % 7;
public static string GetWeekday(int weekday)
return Enum.GetName(typeof(DayOfWeek), weekday);
public static int WeekdaysInFirstOfTheMonth(int year, int day)
for (int i = 1; i <= 12; i++)
if (Weekday.GetWeekday(1, i, year) == day)