How to convert string array to integer array easily using LINQ?

There are times when you would have an array of string with only integer values and you may want to convert them to an integer array.

One technique to do it is to copy the array element one by one to an integer array with the int.tryparse or int.parse.

Below is another simple technique using LINQ to convert string array to integer array USING linq extension method

How to convert string array to integer array easily using LINQ?

using System;

using System.Collections.Generic;

using System.Data;

using System.Linq;

namespace Ginktage

{

internal class Program

{

//How to Convert string array to integer array easily using LINQ ?

private static void Main(string[] args)

{

string [] AbundabtStrArray = new string[] { "98", "12", "82", "1" };

int[] AbundabtIntArray = AbundabtStrArray.Select(int.Parse).ToArray();

foreach (var item in AbundabtIntArray)

Console.WriteLine(item);

Console.ReadLine();

}

}

}
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

1 Response

Leave a Reply