求助:逗号分隔的字符串按数字从小到大排序并成对显示
数量:<input type="text" value="70" name="volume_number">
价格:<input type="text" value="30" name="volume_price">
数量:<input type="text" value="20" name="volume_number">
价格:<input type="text" value="80" name="volume_price">
数量:<input type="text" value="40" name="volume_number">
价格:<input type="text" value="60" name="volume_price">
数量:<input type="text" value="100" name="volume_number">
价格:<input type="text" value="10" name="volume_price">
Request.Form["volume_number"] + Request.Form["volume_price"]
数量和价格总是成对显示的,但总的数量是不确定的
现在的结果是:70,20,40,100,30,80,60,10
想得到的结果:volume_number和volume_price可以成对显示并且volume_number可以按数字的从小到大排序,即:20:80,40:60,70:30,100:10
------解决方案--------------------应该有比这个更简洁的写法
string str = "70,20,40,100,30,80,60,10";
string[] arry = str.Split(',');
var arryNum = arry.Take(arry.Length / 2).ToArray();
var arryPrice = arry.Skip(arry.Length / 2).ToArray();
string res = arryNum.Select((x, i) => x + ":" + arryPrice[i]).OrderBy(x => int.Parse(x.Split(':')[0])).Aggregate((x, y) => x + "," + y);
//结果:res="20:80,40:60,70:30,100:10";