Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I make sure user input must be the same input I need from my array

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading