-1

Here is the code

int checkid = 0; //UserId Name 1
// Array.
string[] Userid = {"John","Bob","Dennis"};
Console.WriteLine("What is your User ID : ");
// Get input.
string InputID = Console.ReadLine();
// If the input is not equal to the first name of the array
// then add 1 to checkid to check the next name.
if (InputID != Userid[checkid])
{
    checkid++;
}
// If the input is equal to a name on userid
// then print Hi! + (InputID).
else if (InputID == Userid[checkid])
{
    Console.WriteLine("Hi! "+ InputID);
}
// If you aren't on the list then it prints error
else
{ 
    Console.WriteLine("Error"); 
}

So I Want to check if the string inputid is equal to any of the names on the array userid but its not working. I Am getting this error message:

CS8600 - Converting null literal or possible null value to non-nullable type.
nevermind
  • 2,300
  • 1
  • 20
  • 36
  • it says that there are build errors and i cant run – GothenBurger Mar 16 '23 at 20:03
  • check https://stackoverflow.com/questions/7867377/checking-if-a-string-array-contains-a-value-and-if-so-getting-its-position. there's a lot of better ways to find element in array – ba-a-aton Mar 16 '23 at 20:04
  • @Austin it is possible OP runs with "treat warnings as errors" flag set (also indeed it is far more likely they read "warning" in the output as "OMG ERROR" :) ) – Alexei Levenkov Mar 16 '23 at 20:15

1 Answers1

0

You can iterate through Userid array like this:

        string[] Userid = {"John","Bob","Dennis"}; //Array
        Console.WriteLine("What is your User ID : ");
        string InputID = Console.ReadLine(); //get input
        for(int i=0;i<Userid.Length;i++)
            if (Userid[i]==InputID)
            {
                Console.WriteLine("Hi! "+ InputID);
                return ;
            }
        Console.WriteLine("Error");