LinQ:list基础操作
1、list去重分组:
List<TcmClinicatWCFService.TCM_SYMPTOMS> listSymptoms = (from a in list group a by new { a.CODE, a.ISO_NAME } into grouping select new TcmClinicatWCFService.TCM_SYMPTOMS { CODE = grouping.Key.CODE, ISO_NAME = grouping.Key.ISO_NAME }).ToList();
2、list取随机:
Random rd = new Random(); List<string> liststr = new List<string>(); liststr.Add("aaa"); liststr.Add("bbb"); liststr.Add("ccc"); liststr.Add("111"); liststr.Add("222"); liststr.Add("333"); //随机一个 var s = liststr.OrderBy(_ => Guid.NewGuid()).First(); //随机两个 var ss = liststr.OrderBy(_ => Guid.NewGuid()).Take(2); //乱序 var sss = liststr.OrderBy(o => rd.Next(0, liststr.Count())).ToList();