Conversion from Int array to string array

InfantPro'Aravind' picture InfantPro'Aravind' · Dec 27, 2012 · Viewed 56.6k times · Source

When I am converting array of integers to array of string, I am doing it in a lengthier way using a for loop, like mentioned in sample code below. Is there a shorthand for this?

The existing question and answers in SO are about int[] to string (not string[]). So they weren't helpful.

While I found this Converting an int array to a String array answer but the platform is Java not C#. Same method can't be implemented!

        int[] intarray =  { 198, 200, 354, 14, 540 };
        Array.Sort(intarray);
        string[] stringarray = { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty};

        for (int i = 0; i < intarray.Length; i++)
        {
            stringarray[i] = intarray[i].ToString();
        }

Answer

Tilak picture Tilak · Dec 27, 2012
int[] intarray = { 1, 2, 3, 4, 5 };
string[] result = intarray.Select(x=>x.ToString()).ToArray();