Advertisement
Statev

StringsSortByLength

Dec 29th, 2011
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace _05.StringsSortByLength
  7. {
  8.     class StringsSortByLength
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Console.Write("Number of words: ");
  13.             int number = int.Parse(Console.ReadLine());
  14.             string[] words = new string[number];
  15.             for (int i = 0; i < number; i++)
  16.             {
  17.                 words[i] = Console.ReadLine();
  18.             }
  19.  
  20.             words = words.OrderBy(word => word.Length).ToArray();
  21.  
  22.             Console.WriteLine("Sorted by length array is:");
  23.             Array.ForEach(words, Console.WriteLine);
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement