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

Your 2020 Plan. Learn 20 minutes a day for 20 days. Online courses from €9.99.

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();

}

}

}

0 thoughts on “How to convert string array to integer array easily using LINQ?

  1. Pingback: InstallShield Limited Edition In The Daily Six Pack: August 19, 2013

Leave a Reply

Your email address will not be published. Required fields are marked *