Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a C# console application that performs the following: 1) Build a method w

ID: 3742226 • Letter: C

Question

Create a C# console application that performs the following:

1) Build a method which reads 3 integers from the console and returns them as an int array (type a number, then hit enter, 3 times).

2) Call this method twice to store 2 local int array variables.

3) Once both arrays are built, write a method which accepts the two arrays and compares the contents to see if they match. If the method returns true (the arrays match), display "Arrays match" in the console. Otherwise, display "Arrays don't match" in the console.

4) Finally, ensure at the end, that the user must hit the enter key in order to exit the program.

Explanation / Answer

using System;

public class Test

{

public static int[] m1(){ //This is the first method to take input and return an array

int[] arr = new int[3];

arr[0] = Convert.ToInt32(Console.ReadLine());

arr[1] = Convert.ToInt32(Console.ReadLine());

arr[2] = Convert.ToInt32(Console.ReadLine());

return arr;

}

public static void m2(int[] a1, int[] a2){ //This is the method that compares the two arrays.

if(a1[0]==a2[0] && a1[1]==a2[1] && a1[2]==a1[2]){

Console.WriteLine("Arrays match");

}else{

Console.WriteLine("Arrays dont match");

}

}

public static void Main()

{

int[] a1 = new int[3];

int[] a2 = new int[3];

a1 = Test.m1();

a2 = Test.m1();

Test.m2(a1, a2);

Console.ReadKey().KeyChar;

}

}