C#数组中找到绝对值最大的是个数
从文本文档导入了一个
字符串数组data[i]; 全是纯数值
求出其中绝对值数值最大的10个数
大家有什么高招?
[解决办法]
int[] arr = new int[11]{1,4,2,8,-9,5,6,3,5,7,-8}; var v = (from i in arr orderby Math.Abs(i) select i).Reverse().Take(10); int[] r = v.ToArray();//r是结果
[解决办法]
data[]是字符串数组
data.Select(s => Convert.ToInt32(s)) 先将数组中每个元素转换为整数
.OrderByDescending(x => Math.Abs(x)) 按最大值倒序排序
.Take(10); 取集合中前10个