c#排序算法结果如果有重复数字只输出其中一个怎么实现
2 回答
慕姐4208626
TA贡献1852条经验 获得超7个赞
用lamb
int[] arr = new int[] { 11, 12, 13, 1, 2, 4, 5, 6, 7, 1, 2, 4, 5 };
var newArr = arr.Distinct().OrderBy(c => c); //去重、升序
foreach (var obj in newArr)
Console.Write("{0,4}", obj);
Console.ReadKey();
德玛西亚99
TA贡献1770条经验 获得超3个赞
List<int> list = new List<int>() { 11, 22, 33, 44, 55, 11 };
list= list.GroupBy(m=>m).Select(m=>m.First()).ToList();
- 2 回答
- 0 关注
- 675 浏览
添加回答
举报
0/150
提交
取消