I'm having problems sorting a list by index using an array as the source of the sort.
Assume there are 5 records set to my class
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));
}
}
My Class definition
class Tests
{
public int iD {get; set;}
public string myString {get; set;}
public Tests (int iD, string myString)
{
this.iD = iD;
this.myString = myString
}
{
What I would like to see come out
record 2
record 1
record 0
record 3
record 4
I tried using the sort function for lists but I couldn't find any examples that used an array as the sort criteria so I'm kind of lost. I appreciate any help offered.
List<Tests> myTests = new List<Tests>;won't compile. Did you meannew List<Tests>();ornew List<Tests>(myInt);?myInt[i]as "the position in the list I want theith element to end up in" or "the original position of the element which I want to place in positioniin the output" (i.e.myInt[0] = 2- does this say "put record 2 in position 0" or "fill position 2 with record 0"?)