Convert String Array to Int Array in C#
-
Use
Array.ConvertAll()
Method to Convert String Array to Int Array inC#
-
Use LINQ’s
Select()
Method to Convert String Array to Int Array inC#

This guide will teach us to convert a string array to an int array in C#.
There are two methods to convert String to int. Both of these methods are quite simple and are very easy to implement.
Use Array.ConvertAll()
Method to Convert String Array to Int Array in C#
Whenever we talk about converting a string to a different data type by understanding its content, it involves parsing. For instance, string 321
can be converted to 321.
The first method you can use is the Array.ConvertAll()
method. Let’s see the implementation of this method.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq;
namespace Array_of_String_to_integer
{
class Program
{
static void Main(string[] args)
{
//method 1 using Array.ConvertAll
string[] temp_str = new string[] { "1000", "2000", "3000" };
int[] temp_int = Array.ConvertAll(temp_str, s => int.Parse(s));
for(int i=0; i<temp_int.Length; i++)
{
Console.WriteLine(temp_int[i]); //Printing After Conversion.............
}
Console.ReadKey();
}
}
}
We use the Array.Convertall()
method in the above code and pass the array. We are parsing the string array into an int array using int.Parse()
.
Output:
1000
2000
3000
Use LINQ’s Select()
Method to Convert String Array to Int Array in C#
We can use the next method to convert a string array to an int array by passing the int.Parse()
method to the LINQ’s Select()
method. We’ll also need to call the ToArray()
method to get the array.
Let’s see the implementation. Learn more about LINQ here.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq;
namespace Array_of_String_to_integer
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("===================Using LINQ=======================================");
// Method Using LINQ.........................
//We can also pass the int.Parse() method to LINQ's Select() method and then call ToArray to get an array.
string[] temp_str = new string[] { "1000", "2000", "3000" };
int[] temp_int1 = temp_str.Select(int.Parse).ToArray();
for (int i = 0; i < temp_int1.Length; i++)
{
Console.WriteLine(temp_int1[i]); //Printing After Conversion.............
}
Console.ReadKey();
}
}
}
Output:
===================Using LINQ=======================================
1000
2000
3000
Haider specializes in technical writing. He has a solid background in computer science that allows him to create engaging, original, and compelling technical tutorials. In his free time, he enjoys adding new skills to his repertoire and watching Netflix.
LinkedInRelated Article - Csharp Array
- Get the Length of an Array in C#
- Sort an Array in C#
- Sort an Array in Descending Order in C#
- Remove Element of an Array in C#
- Convert a String to a Byte Array in C#
- Adding Values to a C# Array