how to compare two arrays c# code example
Example 1: c# merging two arrays
T[] array1 = getOneArray();
T[] array2 = getAnotherArray();
T[] newArray = new T[array1.Length + array2.Length];
Array.Copy(array1, newArray, array1.Length);
Array.Copy(array2, 0, newArray, array1.Length, array2.Length);
Example 2: see if two string arrays are equal c#
bool areEqual = a.SequenceEqual(b);
Example 3: c# compare a variable with an array
bool exists = false;
int checkNum;
int[] myNums = new int[10]
for (int i = 0; i < myNums.Length; i++){
if (checkNum == myNums[i]){
exists = true;
}
}
if (exists){
Console.WriteLine("Your number {0} is in the Array.");
}else{
Console.WriteLine("Your number {0} does not match any number in the Array.");
}