Convert Arraylist Into Array in C#

Why and when we need to convert arraylist into array in C#? If we have some data in RAM memory (arraylists) and want to sort the data in one arraylist by another arraylist (they have to be the same size), we can utilize Array class in C#, but we must convert arraylist into array in C# first. To do so, we can simply use these lines of code:

double[] dbl_array_values1 = alValues1.ToArray(typeof(double)) as double[];
double[] dbl_array_values2 = alValues2.ToArray(typeof(double)) as double[];

Then we can simply sort an array by another in C#, value2 by value1 for example with following line of code:

Array.Sort(dbl_array_values1, dbl_array_values2);

So dbl_array_values1 will be sorted automatically and dbl_array_values2 will be sorted by dbl_array_values1.

External links:

Sort an Array by Another in C# in Stackoverflow
Convert Arraylist Into Array in C# in Dotnetperls

Posted in c-sharp-code-examples Tagged with: ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*