coasterka

CompareCharArrays

Mar 9th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1. static void Main()
  2.         {
  3.             Console.WriteLine("Enter elements of first char array.");
  4.             string firstArrStr = Console.ReadLine();
  5.             Console.WriteLine("Enter elements of second char array.");
  6.             string secondArrStr = Console.ReadLine();
  7.  
  8.             char[] firstArr = firstArrStr.ToCharArray();
  9.             char[] secondArr = secondArrStr.ToCharArray();
  10.  
  11.             int firstArrLength = firstArr.Length;
  12.             int secondArrLength = secondArr.Length;
  13.  
  14.             int minLength = Math.Min(firstArrLength, secondArrLength);
  15.  
  16.             for (int i = 0; i < minLength; i++)
  17.             {
  18.                 if (firstArr[i] == secondArr[i])
  19.                 {
  20.                     continue;
  21.                 }
  22.                 else
  23.                 {                    
  24.                     if (firstArr[i] < secondArr[i])
  25.                     {
  26.                         Console.WriteLine("The first array elements come before the second's.");
  27.                     }
  28.                     else
  29.                     {
  30.                         Console.WriteLine("The second array elements come before the first's.");
  31.                     }
  32.                     break;
  33.                 }
  34.             }
  35.         }
Advertisement
Add Comment
Please, Sign In to add comment