[code]csharpcode:

                List<TrainCourseMsg> indetailTrainMsg=new  List<TrainCourseMsg>();  TrainCourseMsg t = new TrainCourseMsg("课件1",false,true);
		TrainCourseMsg t1 = new TrainCourseMsg("课件1", true, true);
		TrainCourseMsg t2 = new TrainCourseMsg("课件2", false, false);
		TrainCourseMsg t3 = new TrainCourseMsg("课件2", false, true);
		indetailTrainMsg.Add(t);
		indetailTrainMsg.Add(t1);
		indetailTrainMsg.Add(t2);
		indetailTrainMsg.Add(t3);
		//获取字段courseName值相同的数据,返回值为多个数组(一种courseName一个List数组)
		var result1 = from i in indetailTrainMsg group i by i.courseName;
		List<List<TrainCourseMsg>> tt = JsonHelper.DeserializeJsonToList<List<TrainCourseMsg>>(JsonHelper.SerializeObject(result1));//转换成可比遍历类型
		indetailTrainMsg.Clear();//原数据清空
		for (int i = 0; i < tt.Count; i++)
		{
			TrainCourseMsg tm = new TrainCourseMsg();
			for (int j = 0; j < tt[i].Count; j++)//这里遍历每种courseName相同的所有数据,遍历时进行合并操作(想干点啥就干点啥)
			{
				tm.courseName = tt[i][j].courseName;
				tm.isTrain = tt[i][j].isTrain ? tt[i][j].isTrain : tm.isTrain;
				tm.isExam = tt[i][j].isExam ? tt[i][j].isExam : tm.isExam;
			}
			indetailTrainMsg.Add(tm);//合并结束添加进缓存
		}
		
		
		UnityEngine.Debug.Log(JsonHelper.SerializeObject(indetailTrainMsg));

  

posted on 2021-10-09 19:06  陌洛  阅读(51)  评论(0编辑  收藏  举报