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.ja  va 2s  .  c  o 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