Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Is there a way to convert string arrays to int arrays as easy as parsing an string to an int in C#.

int a = int.Parse(”123”);
int[] a = int.Parse(”123,456”.Split(’,’)); // this don't work.

I have tried using extension methods for the int class to add this functionality myself but they don't become static.

Any idea on how to do this fast and nice?

like image 754
Andreas Avatar asked Mar 03 '10 15:03

Andreas


Video Answer


1 Answers

This linq query should do it:

strArray.Select(s => int.Parse(s)).ToArray()
like image 96
Oded Avatar answered Sep 29 '22 05:09

Oded