目标:
大小为[N] [2](或[N,2])的动态数组(每行3个元素,所有元素都是 string )
按第三行排序数组
此时我已经声明了这样的数组:
List<List<string>> testsNamesList = new List<List<string>>();
并添加如下新元素:
testsNamesArray.Add(new List<string>());
testsNamesArray[TestItemNumber].Add("string_1");
testsNamesArray[TestItemNumber].Add("string_2");
testsNamesArray[TestItemNumber].Add("422");
问题1:我不确定,这是二维动态数组创建的最佳实践吗?
问题2:如何按行的第三项对此数组进行排序?
答案 0 :(得分:1)
您可以创建包含3个字符串的 MyRow 类(第一个,第二个和第三个)也许您需要其他类型(现在您将第三列作为int)然后使用
List<MyRow> mycollection;
作为您的收藏品。之后,您可以使用Linq通过
获取排序数据var ordered=mycollection.OrderBy(x=>x.Third);