static void Main(string[] args) { bool validanswer = false; while (!validanswer) { try { string dayOfWeekToday = DateTime.Today.DayOfWeek.ToString(); DaysofWeek currentDay = (DaysofWeek)Enum.Parse(typeof(DaysofWeek), dayOfWeekToday); Console.WriteLine("Enter current day of week:"); string input = Console.ReadLine(); DaysofWeek inputDay = (DaysofWeek)Enum.Parse(typeof(DaysofWeek), input); if (inputDay != currentDay) { Console.WriteLine("Incorrect, today is not " + inputDay); } else { Console.WriteLine("Correct, today is " + inputDay); } validanswer = true; } catch (ArgumentException ex) { Console.WriteLine("Please enter actual day of week"); } } Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("Please provide a number: "); int answer = Convert.ToInt32(Console.ReadLine()); try { DaysofWeek daysOf = (DaysofWeek)answer; }catch(daysOf == 1){ } }
static void Main(string[] args) { Console.WriteLine("Please enter a day of the week: "); string userInput = Console.ReadLine(); try { DaysofWeek input = (DaysofWeek)Enum.Parse(typeof(DaysofWeek), userInput); Console.WriteLine("Thank you. " + input + " is a valid day of the week."); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine("Please enter an actual day of the week."); Console.ReadLine(); } }
public string GetProperty(string strPropertyName, string strFormat, System.Globalization.CultureInfo formatProvider, DotNetNuke.Entities.Users.UserInfo AccessingUser, Scope CurrentScope, ref bool PropertyNotFound) { string OutputFormat = string.Empty; if (strFormat == string.Empty) { OutputFormat = "g"; } PropertyNotFound = true; //Content locked for NoSettings if (CurrentScope == Scope.NoSettings) { return(PropertyAccess.ContentLocked); } string result = string.Empty; bool PublicProperty = true; switch (strPropertyName.ToLower()) { case "month": case "months": { PublicProperty = true; PropertyNotFound = false; result = Months.ToString(formatProvider); break; } case "day": case "days": { PublicProperty = true; PropertyNotFound = false; result = Days.ToString(formatProvider); break; } case "dayofweek": case "daysofweek": { PublicProperty = true; PropertyNotFound = false; result = DaysofWeek.ToString(formatProvider); break; } case "category": { PublicProperty = true; PropertyNotFound = false; result = Category; break; } case "groupname": { PublicProperty = true; PropertyNotFound = false; result = GroupName; break; } case "startdate": { PublicProperty = true; PropertyNotFound = false; result = StartDate.ToString(OutputFormat, formatProvider); break; } case "enddate": { PublicProperty = true; PropertyNotFound = false; result = EndDate.ToString(OutputFormat, formatProvider); break; } case "starttime": { PublicProperty = true; PropertyNotFound = false; result = string.Format(formatProvider, strFormat, TimeSpan.FromMinutes(Convert.ToDouble(StartTime))); break; } case "endtime": { PublicProperty = true; PropertyNotFound = false; result = string.Format(formatProvider, strFormat, TimeSpan.FromMinutes(Convert.ToDouble(EndTime))); break; } case "title": { PublicProperty = true; PropertyNotFound = false; result = Title; break; } case "createdbyuserid": { PublicProperty = true; PropertyNotFound = false; result = CreatedByUserID.ToString(formatProvider); break; } case "createdbyuser": { PublicProperty = true; PropertyNotFound = false; var mc = new ModuleController(); int PortalId = mc.GetModule(ModuleID, -1).PortalID; DotNetNuke.Entities.Users.UserInfo usr = LastModifiedByUser(PortalId); if (usr != null) { result = usr.DisplayName; } break; } case "createddate": case "createdondate": { PublicProperty = true; PropertyNotFound = false; result = CreatedOnDate.ToString(OutputFormat, formatProvider); break; } case "lastmodifiedbyuserid": { PublicProperty = true; PropertyNotFound = false; result = LastModifiedByUserID.ToString(formatProvider); break; } case "lastmodifiedbyuser": { PublicProperty = true; PropertyNotFound = false; var mc = new ModuleController(); int PortalId = mc.GetModule(ModuleID, -1).PortalID; DotNetNuke.Entities.Users.UserInfo usr = LastModifiedByUser(PortalId); if (usr != null) { result = usr.DisplayName; } break; } case "lastmodifiedondate": { PublicProperty = true; PropertyNotFound = false; result = LastModifiedOnDate.ToString(OutputFormat, formatProvider); break; } case "portaltime": { PublicProperty = true; PropertyNotFound = false; result = PortalTime.ToString(OutputFormat, formatProvider); break; } case "usertime": { PublicProperty = true; PropertyNotFound = false; result = UserTime.ToString(OutputFormat, formatProvider); break; } case "utctime": { PublicProperty = true; PropertyNotFound = false; result = UtcTime.ToString(OutputFormat, formatProvider); break; } } if (!PublicProperty && CurrentScope != Scope.Debug) { PropertyNotFound = true; result = PropertyAccess.ContentLocked; } return(result); }