coasterka

CompareCharArrays

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