Answers for "c# compare a variable with an array"

C#
0

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.");
}
Posted by: Guest on January-14-2021

C# Answers by Framework

Browse Popular Code Answers by Language