I am a beginner. I have this problem I am not sure if I will be able to explain it adequately but let’s see:
I have an array called userid and another array called username. I want the user to give me his/her id after that I wish that the name user will type has to be the same array number from the username array
for example if the user types 5 then his/her name must be "f" otherwise user can’t go any further.
I don’t know what to type in if statement?
class Program
{
static void Main(string[] args)
{
string[] userid = {"0" , "1" , "2" , "3" , "4" , "5"};
string[] username = { "a" , "b" , "c" , "d" , "e" , "f"};
Console.Write("please type user id: \t");
string useridreply= Console.ReadLine();
Console.Write("please type user name: \t");
string usernamereply = Console.ReadLine();
if (usernamereply = username[useridreply])
{
}
}
}
>Solution :
in your if-condition you forgot to add one more “=”.
In C# the syntax for comparing two values is “==”.
So your if-condition would look like:
if (usernamereply == username[useridreply])
Here is another helpful link to the microsoft documentation for the comparison operators: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/comparison-operators