在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
C# KeyValuePair<TKey,TValue>的用法。结构体,定义可设置或检索的键/值对。也就是说我们可以通过 它记录一个键/值对这样的值。比如我们想定义一个ID(int类型)和Name(string类型)这样的键/值对,那么可以这 样使用。 model: [Serializable] public class LessonClassModels { public long LessonID { get; set; } public long ClassID { get; set; } public string ClassName { get; set; } public int TeacherUIN { get; set; } public int LessonsNum { get; set; } public long KID { get; set; } /// <summary> /// 班级的上课时间列表(第一个为上课时间,第二个为下课时间) /// </summary> public List<KeyValuePair<DateTime, DateTime>> ClassTimeList { get; set; } }
业务: public List<LessonClassModels> GetLessonClassGroupList(long lessonId)
{
var repository = RepositoryFactory.GetInstance().GetTaokeRepository();
IList<LessonClass> lessonClasses = repository.GetAllLessonClassByLessonId(lessonId);
IEnumerable<IGrouping<long, LessonClass>> groupBy = lessonClasses.GroupBy(u => u.ClassID);
var list = new List<LessonClassModels>();
foreach (IGrouping<long, LessonClass> grouping in groupBy)
{
var models = new LessonClassModels();
var classTimeList = new List<KeyValuePair<DateTime, DateTime>>();
models.ClassID = grouping.Key;
foreach (LessonClass lessonClass in grouping)
{
models.ClassName = lessonClass.ClassName;
models.KID = lessonClass.KID;
models.LessonsNum = lessonClass.LessonsNum;
models.TeacherUIN = lessonClass.TeacherUIN;
var keyPair = new KeyValuePair<DateTime, DateTime>(lessonClass.AttendClassTime, lessonClass.FinishClassTime);
classTimeList.Add(keyPair);
models.ClassTimeList = classTimeList;
}
list.Add(models);
}
return list;
}
页面:
代码
|
请发表评论