static void Main(string[] args) { DaysOfTheWeek ApptDays = DaysOfTheWeek.Monday | DaysOfTheWeek.Wednesday | DaysOfTheWeek.Friday; // loop and HasFlag using list List <string> ldows = Enum.GetNames(typeof(DaysOfTheWeek)).ToList();// convert enum elements to list of string ldows = Enum.GetNames(typeof(DaysOfTheWeek)).ToList(); foreach (string dow in ldows) { DaysOfTheWeek edow; Enum.TryParse(dow, out edow); Console.WriteLine("{0} is {1}included", dow, ApptDays.HasFlag(edow) ? "" : "NOT "); } // loop and HasFlag using Class.Array //Array dows = Enum.GetValues(typeof(DaysOfTheWeek)); // convert enum elements to Class.Array, simpler for HasFlag //foreach (DaysOfTheWeek dow in dows) // Console.WriteLine("{0} is {1}included", dow, ApptDays.HasFlag(dow) ? "" : "NOT "); // alt to HasFlag: if((daysOfTheWeek & DaysOfTheWeek.Monday) == DaysOfTheWeek.Monday) Console.WriteLine(); Console.WriteLine(String.Join(",", ldows)); Console.ReadKey(); }
private static DaysOfTheWeek AddDay(DaysOfTheWeek listofdays, DaysOfTheWeek singleday) { if (!listofdays.HasFlag(singleday)) { return(listofdays | singleday); } return(listofdays); }
private static void daysdoesnotexist(DaysOfTheWeek listofdays) { foreach (var day in (DaysOfTheWeek[])Enum.GetValues(typeof(DaysOfTheWeek))) { if (!listofdays.HasFlag(day)) { Console.WriteLine(day); } } }
public static void PrintDaysWhichDoesNotAppear(DaysOfTheWeek listOfDays) { foreach (DaysOfTheWeek day in Enum.GetValues(typeof(DaysOfTheWeek))) { if (!listOfDays.HasFlag(day)) { Console.WriteLine(day); } } }
private static DaysOfTheWeek RemoveDay(DaysOfTheWeek listofdays, DaysOfTheWeek singleday) { if (listofdays.HasFlag(singleday)) { return(listofdays & ~singleday); } else { return(listofdays); } }
private static IEnumerable <DayOfWeek> GetDaysOfWeek(DaysOfTheWeek daysOfTheWeek) { if (daysOfTheWeek.HasFlag(DaysOfTheWeek.AllDays)) { return(Enum .GetValues(typeof(DayOfWeek)) .Cast <DayOfWeek>() .ToArray()); } else { // Microsoft.Win32.TaskScheduler.DaysOfTheWeek is a flagged enumeration // System.DayOfWeek is not a flagged enumeration // This next statement creates a collection of System.DayOfWeek's based on the name return(Enum .GetValues(typeof(DaysOfTheWeek)) .Cast <DaysOfTheWeek>() .Where(flag => daysOfTheWeek.HasFlag(flag)) .Select(flag => DaysOfTheWeekDictionary[flag]) .ToArray()); } }
private void loadScheduler() { Scheduler scheduler = Scheduler.Load(this.initialBackupName); DaysOfTheWeek dow = scheduler.DaysOfTheWeek; this.checkBoxScheduleMon.Checked = dow.HasFlag(DaysOfTheWeek.Monday); this.checkBoxScheduleTues.Checked = dow.HasFlag(DaysOfTheWeek.Tuesday); this.checkBoxScheduleWeds.Checked = dow.HasFlag(DaysOfTheWeek.Wednesday); this.checkBoxScheduleThurs.Checked = dow.HasFlag(DaysOfTheWeek.Thursday); this.checkBoxScheduleFri.Checked = dow.HasFlag(DaysOfTheWeek.Friday); this.checkBoxScheduleSat.Checked = dow.HasFlag(DaysOfTheWeek.Saturday); this.checkBoxScheduleSun.Checked = dow.HasFlag(DaysOfTheWeek.Sunday); this.checkBoxUseScheduler.Checked = scheduler.Enabled; this.checkBoxSchedulerWhenAvailable.Checked = scheduler.StartWhenAvailable; this.checkBoxSchedulerOnBatteries.Checked = scheduler.StartOnBatteries; }
private static bool DaysAppear(DaysOfTheWeek listofdays, DaysOfTheWeek singleday) { return(listofdays.HasFlag(singleday)); }
public static bool DayAppears(DaysOfTheWeek listOfDays, DaysOfTheWeek singleDay) { return(listOfDays.HasFlag(singleDay)); }
public bool IsToSendOn(DateTimeOffset date) { var dayOfTheWeek = date.DayOfWeek.ToFlag(); return(_chosenDays.HasFlag(dayOfTheWeek)); }