is it possible to elegantly solve the following problem in c#?
Given two arrays of equal length (used for storing different datatypes), __a and __b,
Vector3[] __a = new Vector3[]{new Vector3(0,0,2), new Vector3(0,0,1), new Vector3(0,0,4), new Vector3(0,0,3)};
int[] __b = new int[]{1, 2, 3, 4 };
How can one sort __a and at the same time re-order __b accordingly?
Sorting of __a can be done through System.Array.Sort() or, for example, with the help of LINQ.
After sorting __a, for this example by the z coordinate, the output would be the following: (0,0,1), (0,0,2), (0,0,3), (0,0,4)
And, the __b should have been re-arranged into: 2,1,4,3
this question might look simmilar, but in my current case arrays are always of the same size. Their contents cannot be compared to each other. Instead, moving the elements in __a should result in the same change to the corresponding elements in __b.
This question again relies on comparing internal variables of objects. For this example, I used Vector3 and int datatypes, however, in reality __B can be carrying references to custom objects and cannot be compared.
Is there a way to "extend" the Array.Sort() so that when __a is re-arranged, the __b is re-arranged in exactly the same way? Maybe there is a way to use LINQ?