braBenj
Member
Hello MyBB.
I'm having some trouble with the following code.
I'm trying to figure out how to sort the objects via Name or student number. Simply using the "Array.Sort(studentArray)" method understandably does not work. How do I specify which fields I want to sort the objects by?
I'm new to C# and really new to OOP concepts so I apologize if I haven't phrased my question properly, but I hope you get the idea.
I'm having some trouble with the following code.
Code:
class Students
{
public string Name { set; get; }
public int stuNum { set; get; }
static void Main(string[] args)
{
Students[] studentArray = new Students[4];
for (int i = 0; i < studentArray.Length; i++)
{
studentArray[i] = new Students();
}
studentArray[0].Name = "cccc";
studentArray[1].Name = "aaaa";
studentArray[2].Name = "bbbb";
studentArray[3].Name = "dddd";
studentArray[0].stuNum = 4444;
studentArray[1].stuNum = 2222;
studentArray[2].stuNum = 3333;
studentArray[3].stuNum = 1111;
}
}
I'm trying to figure out how to sort the objects via Name or student number. Simply using the "Array.Sort(studentArray)" method understandably does not work. How do I specify which fields I want to sort the objects by?
I'm new to C# and really new to OOP concepts so I apologize if I haven't phrased my question properly, but I hope you get the idea.
