Advertisement
APXOHT

Untitled

Jan 6th, 2013
1,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1. using System;
  2.  
  3. class CompareCharArrays
  4. {
  5.     static void Main()
  6.     {
  7.         char[] firstArray = { 'P', 'e', 's', 'h' };
  8.         char[] secondArray = { 'P', 'e', 's', 'h', 'o' };
  9.         int maxLenght;
  10.         int smallerArray = 0;
  11.         if (firstArray.Length <= secondArray.Length)
  12.         {
  13.             maxLenght = firstArray.Length;
  14.         }
  15.         else
  16.         {
  17.             maxLenght = secondArray.Length;
  18.         }
  19.  
  20.         for (int i = 0; i < maxLenght; i++)
  21.         {
  22.             if (firstArray[i] < secondArray[i])
  23.             {
  24.                 smallerArray = 1;
  25.                 break;
  26.             }
  27.             else if (firstArray[i] > secondArray[i])
  28.             {
  29.                 smallerArray = 2;
  30.                 break;
  31.             }
  32.         }
  33.  
  34.         if (smallerArray == 1)
  35.         {
  36.             Console.WriteLine("The first array is earlier.");
  37.         }
  38.         else if (smallerArray == 2)
  39.         {
  40.             Console.WriteLine("The second array is earlier.");
  41.         }
  42.         else
  43.         {
  44.             if (firstArray.Length > secondArray.Length)
  45.             {
  46.                 Console.WriteLine("The second array is earlier.");
  47.             }
  48.             else if (firstArray.Length < secondArray.Length)
  49.             {
  50.                 Console.WriteLine("The first array is earlier.");
  51.             }
  52.             else
  53.             {
  54.                 Console.WriteLine("The two arrays are the same.");
  55.             }
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement