【发布时间】:2013-10-16 20:39:37
【问题描述】:
我需要帮助对我拥有的列表进行排序....
我有这份清单
List<List<string>> PlayerList= new List<List<string>>();
填充后我会有类似的东西
[123112412,John,225,123.5522,Dalas]
[123312,Fred,12,43.5522,Chicago]
然后我可以访问例如:
PlayerList[0][1] = John
PlayerList[1][1] = Fred
现在的问题...我需要按第 4 个字段对这个“PlayerList”进行排序...我该怎么做...我真的迷失了 C#。
我需要输出类似于:
[123312,Fred,12,43.5522,Chicago]
[123112412,John,225,123.5522,Dalas]
提前致谢。
【问题讨论】:
-
我认为排序后的列表将是
sorted = PlayerList.OrderBy(list=>list[4]).ToList(); -
无需在标题中包含 C# / Unity,因为您将它们作为标签
-
对不起,第一个问题...
-
不要忘记您可以定义自己的数据结构。
List<List<string>>可以很容易地成为List<MyCustomClass>。哪个更清楚:PlayerList[0][1]或PlayerList[0].name? -
很好......我也试试...... tks
标签: c# list sorting unity3d sql-order-by