Advertisement
Kyojin96

Compare char arrays

Mar 6th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. namespace ConsoleApplication2
  2. {
  3.     using System;
  4.  
  5.     class Program
  6.     {
  7.         static void Main()
  8.         {
  9.             string notEqual = "Arrays are not equal";
  10.  
  11.             //Input for arrays
  12.             Console.Write("First array: ");
  13.             string firstArr = Console.ReadLine();
  14.  
  15.             Console.Write("Second array: ");
  16.             string secondArr = Console.ReadLine();
  17.  
  18.             int equalCharacters = 0;
  19.  
  20.             if (firstArr.Length == secondArr.Length)
  21.             {
  22.                 for (int i = 0; i < firstArr.Length; i++)
  23.                 {
  24.                     if (firstArr[i] == secondArr[i])
  25.                     {
  26.                         equalCharacters++;
  27.                     }
  28.                     else
  29.                     {
  30.                         Console.WriteLine(notEqual);
  31.                         break;
  32.                     }
  33.                 }
  34.  
  35.                 if (equalCharacters == firstArr.Length)
  36.                 {
  37.                     Console.WriteLine("Arrays are equal!");
  38.                 }
  39.             }
  40.             else
  41.             {
  42.                 Console.WriteLine(notEqual);
  43.             }
  44.  
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement