我在使用数组作为排序源按索引对列表进行排序时遇到问题。
假设我的班级有 5 条记录
class Program
{
static void Main(string[] args)
{
int[] myInt {2,1,0,3,4}
List<Tests> myTests = new List<Tests>;
//this part doesn't work
for (int i = 0; i < 4; i++)
{
myInt[i] = myTests[i];
}
myTests.ForEach(i => Console.WriteLine("{0} {1}", i.id, i.myString));
}
}
我的班级定义
class Tests
{
public int iD {get; set;}
public string myString {get; set;}
public Tests (int iD, string myString)
{
this.iD = iD;
this.myString = myString
}
{
我想看到的出来
record 2
record 1
record 0
record 3
record 4
我尝试对列表使用排序函数,但我找不到任何使用数组作为排序标准的示例,所以我有点迷路了。我感谢提供的任何帮助。