new List<string[]> list = new List<string[]>();
for (int i = 0; i < contentList.Count; i++) //contentList is a list which can have many rows of data...
{
string str1 = contentList[i].Quicklink; // Get data 1
string str2 = contentList[i].Title; // Get data 2
list.Add(new[] { str1, str2 });
}
//SORT THE LIST based by `str2`
for (int p = 0; p < list.Count; p++)
{
Label1.Text += str1 + " " + str2 "\r\n";;
}
Run Code Online (Sandbox Code Playgroud)
如何根据str2值对列表进行排序,然后将键对值分配给标签.
为此你有linq:
var sorted = list.OrderBy(item => item[1]);
Run Code Online (Sandbox Code Playgroud)
然后你可以这样做:
foreach(var item in sorted)
Label1.Text += item[0] + " " + item[1] + "\r\n"; //forgot the "+"
Run Code Online (Sandbox Code Playgroud)