svetlozar_kirkov

Compare Arrays for Equality (Exercise)

Sep 30th, 2014
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ConsoleTesting
  5. {
  6.     internal class ConsoleTesting
  7.     {
  8.         private static void Main()
  9.         {
  10.             Console.Write("Enter the length of first array: ");
  11.             int n = int.Parse(Console.ReadLine());
  12.             Console.Write("Enter the length of second array: ");
  13.             int p = int.Parse(Console.ReadLine());
  14.  
  15.             if (n != p)
  16.             {
  17.                 Console.WriteLine("Array Lengths are not equal!");
  18.             }
  19.             else
  20.             {
  21.                 var arrayOne = new int[n];
  22.                 var arrayTwo = new int[p];
  23.  
  24.                 for (int i = 0; i < n; i++)
  25.                 {
  26.                     Console.Write("Enter int for index \"{0}\" in Array One: ", i);
  27.                     arrayOne[i] = int.Parse(Console.ReadLine());
  28.                 }
  29.  
  30.                 for (int i = 0; i < p; i++)
  31.                 {
  32.                     Console.Write("Enter int for index \"{0}\" in Array Two: ", i);
  33.                     arrayTwo[i] = int.Parse(Console.ReadLine());
  34.                 }
  35.  
  36.                 bool isEqual = arrayOne.SequenceEqual(arrayTwo);
  37.  
  38.                 if (isEqual)
  39.                 {
  40.                     Console.WriteLine("Both arrays are equal!");
  41.                 }
  42.                 else
  43.                 {
  44.                     Console.WriteLine("Arrays are not equal!");
  45.                 }
  46.             }
  47.            
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment