static void Main(string[] args) { WeekEnum day = WeekEnum.Fri; switch (day) { case WeekEnum.Mon: Console.WriteLine("Go!"); break; case WeekEnum.Tue: Console.WriteLine("Try your best!"); break; case WeekEnum.Wed: Console.WriteLine("Little Saturday night!"); break; case WeekEnum.Thu: Console.WriteLine("Still going strong!"); break; case WeekEnum.Fri: Console.WriteLine("TGIF!"); break; case WeekEnum.Sat: Console.WriteLine("Sleep all day, sleep all night!"); break; case WeekEnum.Sun: Console.WriteLine("Ready.. Set.."); break; default: break; } }
CalendarViewModel getCalendarViewModel(DateTime date, WeekEnum week) { var weekStartDate = DateHelper.GetWeekStartDate(date, week); var weekDates = DateHelper.GetWeekDays(weekStartDate); var calendarDaysModelList = weekDates .Select(d => new CalendarViewDayModel { TextColor = Theme.Current.TodayCalendarBaseTextColor, Day = d.Day, Month = d.Month, Year = d.Year }); return(new CalendarViewModel(this) { Days = new ObservableCollection <CalendarViewDayModel>(calendarDaysModelList), Month = weekStartDate.Month, Year = weekStartDate.Year }); }
static void Main(string[] args) { WeekEnum wek = WeekEnum.周二; //枚举->数值 Console.WriteLine((int)wek);//结果:1 //数值 -> 枚举类型 int holiday = 6; //将数值转换为枚举类型的变量 wek = (WeekEnum)Enum.Parse(typeof(WeekEnum), holiday.ToString()); Console.WriteLine(wek);//结果:周天 //数值 -> 枚举字符串 string wekStr = Enum.GetName(typeof(WeekEnum), 5); Console.WriteLine(wekStr);//结果:周六 /*==================================================================*/ //三元运算符 等价于 if。。。else。。。分支 string name = "admin"; bool result; //下面代码中的if else结构和三元表达式的含义是一致的 if (name == "admin") { result = true; } else { result = false; } result = (name == "admin") ? true : false; Console.ReadKey(); }
int getCalendarPosition(int boundaryPosition, WeekEnum week) { int removePosition; int calculatedPosition; if (boundaryPosition == _maximumCalendarPosition) { removePosition = _minimumCalendarPosition; calculatedPosition = _maximumCalendarPosition - 1; } else { removePosition = _maximumCalendarPosition; calculatedPosition = _minimumCalendarPosition + 1; } var date = CalendarList[boundaryPosition].Date; var weekViewModel = getCalendarViewModel(date, week); CalendarList.RemoveAt(removePosition); CalendarList.Insert(boundaryPosition, weekViewModel); return(calculatedPosition); }
public void test() { WeekEnum sunday = WeekEnum.Sunday; //枚举类型转换其他类型 //枚举类型 -> 字符串整数 Assert.AreEqual( "1", Enum.Format(typeof(WeekEnum), WeekEnum.Sunday, "d") ); Assert.AreEqual( "1", sunday.ToString("D") ); //error 格式字符串只能是“G”、“g”、“X”、“x”、“F”、“f”、“D”或“d” //Assert.AreEqual("01",sunday.ToString("D2")); //枚举类型 --> 整数 Assert.AreEqual( 1, (int)WeekEnum.Sunday ); //枚举类型 -> 字符串 Assert.AreEqual( "Sunday", Enum.GetName(typeof(WeekEnum), sunday) ); Assert.AreEqual( "Sunday", sunday.ToString() ); //其他类型转枚举类型 //字符串 -> 枚举类型 Assert.AreEqual( WeekEnum.Sunday, Enum.Parse(typeof(WeekEnum), "Sunday") ); //字符串 -> 枚举类型 Assert.AreEqual( WeekEnum.Sunday, Enum.Parse(typeof(WeekEnum), "1") ); //获取所有值 //GetNames 获取枚举类型的名 Assert.AreEqual( "Sunday Monday Tuesday Wednesday Thursday Friday Saturday", string.Join(" ", Enum.GetNames(typeof(WeekEnum)) ) ); //获取所有的值 Assert.AreEqual( WeekEnum.Sunday, Enum.GetValues(typeof(WeekEnum)).GetValue(0) ); }
public static TrainingScheduleSViewtructure CreateTrainingScheduleSViewtructure(WeekEnum week) { var model = TrainingScheduleService.GetTrainingSchedule((int)week); if (model == null) { var empty = new TrainingScheduleSViewtructure { Week = (int)week, WeekName = week.ToString(), Off = false }; return(empty); } var trainingScheduleStructure = JsonConvert.DeserializeObject <TrainingScheduleStructure>(model.TrainingMenu); var trainingScheduleViewStructure = new TrainingScheduleSViewtructure { Week = (int)week, WeekName = week.ToString(), Off = trainingScheduleStructure.Off }; var trainingListViewStructureList = new List <TrainingListViewStructure>(); int count = 1; foreach (var training in trainingScheduleStructure.TrainingContentList) { var trainingListViewStructure = new TrainingListViewStructure { TrainingId = training.TrainingId, TrainingNo = count, TrainingName = TrainingMasterService.GetTrainingMasterData(training.TrainingId).TrainingName, TrainingSetCount = training.TrainingSetCount }; var loadContentViewStructureList = new List <LoadContentViewStructure>(); foreach (var load in training.LoadContentList) { var loadContentViewStructure = new LoadContentViewStructure { LoadId = load.LoadId, LoadName = LoadService.GetLoad(load.LoadId).LoadName, Nums = load.Nums.ToString(), LoadUnitId = load.LoadUnitId, LoadUnitName = LoadUnitService.GetLoadUnit(load.LoadUnitId).UnitName }; loadContentViewStructureList.Add(loadContentViewStructure); } trainingListViewStructure.LoadContentList = loadContentViewStructureList; trainingListViewStructureList.Add(trainingListViewStructure); count++; } trainingScheduleViewStructure.TrainingContentList = trainingListViewStructureList; return(trainingScheduleViewStructure); }