This post will discuss how to convert a string array to an integer array in C#.

1. Using Array.ConvertAll() method

C# provides the Array.ConvertAll() method for converting an array of one type to another type. We can use it as follows to convert a string array to an integer array:

Download  Run Code

 
We can improve the above code by using a method group in place of a lambda expression.

Download  Run Code

 
The int.Parse() method throws a FormatException if the string is not numeric. A better alternative is to call the Int32.TryParse() method. If the conversion operation fails, this method does not throw an exception and returns false. We can use this information to provide a default value when the conversion is failed for any member of the string array.

Download  Run Code

3. Using LINQ

We can also pass the int.Parse() method to LINQ’s Select() method and then call ToArray to get an array.

Download  Run Code

That’s all about converting a string array to an int array in C#.