static void Main(string[] args) { //prompt the user for a day of the week Console.WriteLine("Please enter a day of the week (i.e. Tuesday, Friday"); //parse the day of the week into an enum string userInput = Console.ReadLine(); daysOfTheWeek day = (daysOfTheWeek)Enum.Parse(typeof(daysOfTheWeek), userInput); //print out a message based ont he day of the week switch (day) { case daysOfTheWeek.Sunday: { Console.WriteLine("#beatyourmeat Sunday!"); break; } case daysOfTheWeek.Monday: { Console.WriteLine("We actually like Mondays"); break; } case daysOfTheWeek.Tuesday: { Console.WriteLine("Clubs goin' up on a Tuesday!"); break; } case daysOfTheWeek.Wednesday: { Console.WriteLine("Whiskey Wednesday"); break; } case daysOfTheWeek.Thursday: { Console.WriteLine("Thristy Thursday"); break; } case daysOfTheWeek.Friday: { Console.WriteLine("Freak out for Fridays"); break; } case daysOfTheWeek.Saturday: { Console.WriteLine("Sidetrack Saturdays"); break; } default: { Console.WriteLine("Not sure how you got here."); break; } } }
static void Main(string[] args) { try { Console.WriteLine("Please type in the current day of the week."); string userInput = Console.ReadLine().ToLower(); daysOfTheWeek day = (daysOfTheWeek)Enum.Parse(typeof(daysOfTheWeek), userInput); } catch (FormatException ex) { Console.WriteLine("Please enter an actual day of the week. " + ex.Message); } catch (ArgumentException ex) { Console.WriteLine("Please enter an actual day of the week. " + ex.Message); } catch (Exception ex) { Console.WriteLine("Please enter an actual day of the week. " + ex.Message); } finally { Console.WriteLine("Please enter an actual day of the week."); } Console.ReadLine(); }
static void Main(string[] args) { try { Console.WriteLine("Hello user, what is the current day of the week? (type 1 for monday, 2 for sunday and so on)"); var answer = Convert.ToChar(Console.ReadLine()); string value; value = answer.ToString(); daysOfTheWeek day = (daysOfTheWeek)Enum.Parse(typeof(daysOfTheWeek), value); if (day == daysOfTheWeek.monday) { Console.WriteLine("The day is monday"); } if (day == daysOfTheWeek.tuesday) { Console.WriteLine("The day is tuesday"); } if (day == daysOfTheWeek.wednesday) { Console.WriteLine("The day is wednesday"); } if (day == daysOfTheWeek.thursday) { Console.WriteLine("The day is thursday"); } if (day == daysOfTheWeek.friday) { Console.WriteLine("The day is friday"); } if (day == daysOfTheWeek.saturday) { Console.WriteLine("The day is saturday"); } if (day == daysOfTheWeek.sunday) { Console.WriteLine("The day is sunday"); } } catch (Exception ex) { Console.WriteLine("Please enter an actual day of the week, remember there are only SEVEN days in a week..."); } finally { Console.ReadLine(); } Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("What is the current day of the week?\n"); string CurrentDay = Convert.ToString(Console.ReadLine()).ToLower(); try { daysOfTheWeek day = (daysOfTheWeek)Enum.Parse(typeof(daysOfTheWeek), CurrentDay); Console.WriteLine("\nToday is " + char.ToUpper(CurrentDay[0]) + CurrentDay.Substring(1)); } catch (Exception e) { Console.WriteLine("\nPlease enter an actual day of the week."); } Console.ReadLine(); }
private static void Main() { try { Console.WriteLine("What day is it today?"); string day = Console.ReadLine(); daysOfTheWeek dayOfTheWeek = (daysOfTheWeek)Enum.Parse(typeof(daysOfTheWeek), day); Console.WriteLine("That's Awesome!!"); Console.ReadLine(); } catch (Exception) { Console.WriteLine("That is invalid. Please enter an actual day of the week"); Console.ReadLine(); } }
static void Main(string[] args) { Console.WriteLine("Enter the current day of the week"); string userInput = Console.ReadLine(); try { daysOfTheWeek day = (daysOfTheWeek)Enum.Parse(typeof(daysOfTheWeek), userInput, true); Console.WriteLine("you entered: " + day); Console.ReadLine(); } catch (Exception) { Console.WriteLine("Please enter an actual day of the week."); Console.ReadLine(); } }
static void Main(string[] args) { Console.WriteLine("what day is it?:"); string value = Console.ReadLine(); try { daysOfTheWeek day = (daysOfTheWeek)Enum.Parse(typeof(daysOfTheWeek), value); Console.WriteLine("Its " + value); } catch (Exception) { Console.WriteLine("Please enter an actual day"); Console.ReadLine(); } Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("Enter the current day of the week");//prompt user to enter day of the week string day = Console.ReadLine(); try //Wrap in try/catch block, print to console error message if error occurs { daysOfTheWeek days = (daysOfTheWeek)Enum.Parse(typeof(daysOfTheWeek), day); // Assign the value/values to the variable of the enum data type Console.WriteLine("Today's day is {0}", day); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine("Please enter an actual day of the week."); Console.ReadLine(); } }
static void Main(string[] args) { Console.WriteLine("Enter the current day of the week"); string day = Console.ReadLine(); try { daysOfTheWeek days = (daysOfTheWeek)Enum.Parse(typeof(daysOfTheWeek), day); Console.WriteLine("Today's day is {0}", day); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine("Please enter an actual day of the week."); Console.ReadLine(); } }
static void Main(string[] args) { Console.WriteLine("Enter the current day of the week. \n Use correct format then press Enter:"); string userInput = Console.ReadLine(); daysOfTheWeek days = (daysOfTheWeek)Enum.ToObject(typeof(daysOfTheWeek), 7); try { days = (daysOfTheWeek)Enum.Parse(typeof(daysOfTheWeek), userInput); { Console.WriteLine("You entered: " + days); } } catch (Exception) { Console.WriteLine("Please enter an actual day of the week. (Capitalize correctly)"); } Console.ReadLine(); }
static void Main(string[] args) { int attempts = 0; do { try { Console.WriteLine("What day of the week is today?"); string todayIS = Console.ReadLine(); daysOfTheWeek today = Days_of_the_Week.ParseEnum <daysOfTheWeek>(todayIS); Console.WriteLine(today); } catch { attempts++; Console.WriteLine("Please enter an actual day of the week."); } }while (attempts < 5); Console.ReadLine(); }
static void Main(string[] args) { TextInfo textInfo = new CultureInfo("en-US", false).TextInfo; try { Console.WriteLine("Please enter the current day of the week"); string dayString = Console.ReadLine(); dayString = textInfo.ToTitleCase(dayString); daysOfTheWeek day = (daysOfTheWeek)Enum.Parse(typeof(daysOfTheWeek), dayString); Console.WriteLine(day.ToString()); Console.WriteLine((int)day); Console.ReadLine(); } catch (Exception) { Console.WriteLine("Please enter an actual day of the week in english."); Console.ReadLine(); } }