# How do you link two arrays?

I'm in a basic programming class, and everything is done in pseudo code.

My question is this: How do you link two arrays?

I have a single-dimensional array that lists students names, and I have a two-dimensional array that lists the top eight scores of each student...this is all fine and dandy, but now I need to sort the arrays by the students name. I'm poked around online and read through the books chapter twice, it only briefly mentions linking two arrays but shows no examples.

If it's any help, we are using bubble-sorting, and that is what I am fairly familiar with...I can sort the names, that's the easy part, but I don't know how to sort the grades so they do not go out of order.

Thanks for the input!

Sidenote: I got it figured out! I ended up doing how Greg Hewgill had mentioned. As I put in my comment to his suggestion, I started randomly throwing in lines of code until that idea hit me...it doesn't look pretty (one module swapped the names, another to swap the grades, and a third even then to swap the individual students grades earlier on in a multidimensional array), but it indeed seemed to work...no way to test it in a language as I have no compiler nor have I enough knowledge to make the pseudo code into actual code if I were to download one, but it sounds really good on the paper I typed it out on!

As I also mentioned in the note, I do thank everyone for their speedy and helpful insight, I actually didn't even think I'd get a reply tonight, thank you everyone again for all your help!

Jeffrey

What you may want to do is the following: As you're sorting the names and you have to swap two positions, do the same swap in the array of scores. That way, all changes that you make to the names array will be reflected in the scores array. When you're done, the scores will be in the same sorted order as the names are.

There are more effective ways of doing this with different data structures, as other comments will show.

Define a simple Student class like this:

```public class Student : IComparable<Student>
{
public string Name { get; set; }
public int[] Scores { get; set; }

#region IComparable<Student> Members

public int CompareTo(Student other)
{
// Assume Name cannot be null
return this.Name.CompareTo(other.Name);
}

#endregion
}
```

then even simpler

```    var students = new[] {
new Student(){ Name = "B", Scores = new [] { 1,2,3 } },
new Student(){ Name = "C", Scores = new [] { 3,4,5 } },
new Student(){ Name = "A", Scores = new [] { 5,6,7 } }
};

Array.Sort(students);
```

will do the work for you.