CSharp - Converting an Array of Strings to Integers and Sorting It

Description

Converting an Array of Strings to Integers and Sorting It

Demo

using System;  
using System.Linq;  
class Program//from  w  ww . j  av  a2 s  .co m
{
    static void Main(string[] args)
    {
        string[] numbers = { "0042", "010", "9", "27" };  
          
        int[] nums = numbers.Select(s => Int32.Parse(s)).OrderBy(s => s).ToArray();  
          
        foreach(int num in nums)  
          Console.WriteLine(num);  
              
    }
}

Result

Related Topic