c# convert string to int array code example

Example 1: convert string array to int C#

using System;

public class Example
{
	public static void Main()
	{
		string[] strings = new string[] {"1", "2", "3"};

		int[] ints = Array.ConvertAll(strings, s => int.Parse(s));
		Console.WriteLine(String.Join(",", ints));
	}
}

Example 2: c# how to convert string to int

var myInt = int.Parse("123"); // this one throw exception if the argument is not a number
var successfullyParsed = int.TryParse("123", out convertedInt); //this returns true if the convertion has been successfully done (integer is stored in "convertedInt"), otherwise false.

Example 3: convert array from string to int c#

string[] strings = new string[] {"1", "55", "3"}

int[] asIntegers = Array.ConvertAll(strings, int.Parse);

Example 4: c# convert enumb to int array

int[] result = enumArray.Cast<int>().ToArray();