Converting an Array of Strings to Integers and Sorting It

image_pdfimage_print
   
 

using System;
using System.Linq;
public class MainClass {
    public static void Main() {

        string[] numbers = { "0042", "010", "9", "2q7" };

        int[] nums = numbers.Select(s => Int32.Parse(s)).OrderBy(s => s).ToArray();

        foreach (int num in nums)
            Console.WriteLine(num);
    }
}

    


This entry was posted in LINQ. Bookmark the permalink.