本文介绍了C#按值排序数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我有一个值列表
200000
90000
500000
60000
150000
我需要对它进行排序
60000
90000
150000
200000
500000
我正在使用ArrayList Sort并将其排序为
150000
200000
500000
60000
90000
Hi there,
I have a list of values
200000
90000
500000
60000
150000
I need to sort it
60000
90000
150000
200000
500000
I am using an ArrayList Sort and it sorting it as
150000
200000
500000
60000
90000
public void OrderDropDowns(ref DropDownList objDDL)
{
// ArrayList to keep text and value items within the specified Drop Down
ArrayList text_list = new ArrayList();
ArrayList value_list = new ArrayList();
foreach (ListItem li in objDDL.Items)
{
if (li.Text != "-Select One-")
{
text_list.Add(li.Text);
}
}
if (text_list.Count >= 8)
{
text_list.Sort(0, 4, null);
}
else
{
text_list.Sort();
}
foreach (object li in text_list)
{
string value = objDDL.Items.FindByText(li.ToString()).Value;
value_list.Add(value);
}
// Adding Sorted Items to the Drop Down List
objDDL.Items.Clear();
objDDL.Items.Add("-Select One-");
for (int i = 0; i < text_list.Count; i++)
{
if (i != text_list.Count)
{
ListItem objItem = new ListItem(text_list[i].ToString(), value_list[i].ToString());
objDDL.Items.Add(objItem);
}
}
}
Any help would do please
推荐答案
int[] intArray = { 8, 10, 2, 6, 3 };
// Sort your int array
Array.Sort(intArray);
foreach (var i in intArray)
{
Console.WriteLine(i);
}
// Sort it the other way
foreach (var i in intArray.Reverse())
{
Console.WriteLine(i);
}
按属性订购对象:
order objects by property:
MyCollection.OrderBy(o => o.PropertyName);
MyCollection.OrderByDescending(o => o.PropertyName);
var sortedList = list.Cast<string>().OrderBy(item => int.Parse(item));
检查一下.
http://stackoverflow.com/questions/852439/how-to-sort-elements-of-array-list-in-c-sharp [ ^ ]
Check this.
http://stackoverflow.com/questions/852439/how-to-sort-elements-of-array-list-in-c-sharp[^]
这篇关于C#按值排序数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!