Advertisement
stak441

MultidimensionalArrays - problem 5

Jan 15th, 2013
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace _05.StringLength
  7. {
  8.     class StringLength
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string[] stringArray = { "ha", "haha", "hihihi", "hoh", "hohohohohohoh" };
  13.  
  14.             SortBySize(stringArray);
  15.         }
  16.  
  17.         static void SortBySize(string[] stringArray)
  18.         {
  19.             int n = stringArray.Length;
  20.             int[] sizes = new int[n];              //This will hold the size of each string
  21.  
  22.             for (int i = 0; i < n; i++)
  23.             {
  24.                 sizes[i] = stringArray[i].Length;
  25.             }
  26.  
  27.             Array.Sort(sizes, stringArray);       //Sorts the second array, according to the "keys" in the first (ascending)
  28.  
  29.             foreach (var element in stringArray)
  30.             {
  31.                 Console.WriteLine(element);
  32.             }
  33.  
  34.  
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement