日期:2014-05-18 浏览次数:20843 次
var result = list1.Select((n, i) => new { name = n, index = i }).Where(x => x.name == "张三").Select(x => x.index).ToList();
------解决方案--------------------
List<string> list1 = new List<string> { "张三", "李四", "张三", "王二", "小王", "小仓", "张三", "小刘" }; var name=from m in list1 where m=="张三" select m; list1 = name.ToList();
------解决方案--------------------
List<string> list1 = new List<string> { "张三", "李四", "张三", "王二", "小王", "小仓", "张三", "小刘" }; list1 = list1.Select((s, index) => new { s, sindex = index.ToString() }).Where(v => v.s == "张三").Select(x => x.sindex.ToString()).ToList();
------解决方案--------------------
var index = 0; var result = (from x in list1 let ndx = index++ where x == "张三" select ndx).ToList();
------解决方案--------------------
List<string> list1 = new List<string> { "张三", "李四", "张三", "王二", "小王", "小仓", "张三", "小刘" };
List<string> list2 = list1.Where(t => t.Trim() == "张三").ToList();