与C#一样,将值排序为双值 [英] Sorting values double values as in C#
本文介绍了与C#一样,将值排序为双值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我已将变量声明为字符串,并在其中放置了双精度值.例如
Hi All,
I have declared a variable as string and placed double values in that. e.g.
string Numbers=string.Emtpy;
Numbers="128";
Numbers="124";
Numbers="122";
Numbers="121";
Numbers="120";
Numbers="";
Numbers="117";
现在,我想根据无值对这个变量进行排序.
我想要的结果是:
Now I want to sort this variable as on the basis of no values.
I want result as:
Numbers="";
Numbers="117";
Numbers="120";
Numbers="121";
Numbers="122";
Numbers="124";
Numbers="128";
请帮忙
Mohd Wasif
Please help
Mohd Wasif
推荐答案
不确定您是否正在寻找这个,不过请看以下CP中的文章:
以C#排序的数字字符串 [ http://www.dotnetperls.com/sort-number-strings [
Not sure if you are exactly looking for this, nevertheless have a look at below article in CP:
Numeric String Sort in C#[^]
http://www.dotnetperls.com/sort-number-strings[^]
检查此
Hi ,
Check this
string[] Numbers = new string[6];
Numbers[0] = "128";
Numbers[1] = "";
Numbers[2] = "122";
Numbers[3] = "121";
Numbers[4] = "120";
Numbers[5] = "117";
var res = (from x in Numbers
orderby x ascending
select x).ToList();
GridView1.DataSource = res;
GridView1.DataBind();
最好的问候
M.Mitwalli
Best Regards
M.Mitwalli
那是行不通的.您的代码创建一个字符串,然后重复覆盖当前值,仅保留最终的"117"值.
而是使用列表或数组来保存多个字符串:
That isn''t going to work. Your code creates a string, then overwrites the current value repeatedly, leaving only the final "117" value.
Instead, look at using a List or an Array to hold multiple strings:
string[] arrayOfStrings = new string[] { "128", "124", "122", "121", "120", "", "117" };
Array.Sort(arrayOfStrings);
List<string> listOfStrings = new List<string>();
listOfStrings.Add("128");
listOfStrings.Add("124");
listOfStrings.Add("122");
listOfStrings.Add("121");
listOfStrings.Add("120");
listOfStrings.Add("");
listOfStrings.Add("117");
listOfStrings.Sort();
该列表更加灵活,因为您无需随时知道条目数-您可以添加更多.
The list is more flexible, as you don''t need to know the number of entries at any time - you can just add more.
这篇关于与C#一样,将值排序为双值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文