Convert a String Array to an int Array.
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | using System; using System.Linq; class Program { static void Main(string[] args) { //this line create a string variable. string[] stringOfInteger = { "1", "5", "10", "15", null, "", "20", "25", "30" }; //create an integer data type array. int[] intArray = (from x in stringOfInteger where x != "" && x!= null select int.Parse(x)).ToArray(); Console.WriteLine("elements of int array............"); foreach (int x in intArray) { Console.WriteLine("{0} => {1}",x, x.GetType()); } Console.ReadLine(); } } |
Output:
