C# string[] to int[] [duplicate] C# string[] to int[] [duplicate] arrays arrays

C# string[] to int[] [duplicate]


This linq query should do it:

strArray.Select(s => int.Parse(s)).ToArray()


int[] a = Array.ConvertAll("123,456".Split(','), s => Int32.Parse(s));

Should do just fine. You could modify the lambda to use TryParse if you don't want exceptions.


int[] a = "123,456".Split(’,’).Select(s => int.Parse(s)).ToArray();