0
I want to check a string to an if value.
I ask the user to enter a word. I have the word saved as a string. How to ( use an if statement to) check if the word entered is the the word I want the user to enter. Eg String yourName; YourName = Console.ReadLine(); Console.WriteLine("your name is {0}", yourName); If (YourName == Mike) //not sure { Console.WriteLine("You can enter"); } Else { Console.WriteLine("your name is wrong"); I am getting an error. What am I doing wrong
6 Respuestas
+ 1
Yeah replace your if statment with this: If (YourName.Equals(“Mike”));
0
YourName.equals(“Mike”) will compare string words
0
This will go inside the if bracket?
0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("what are you doing");
           string stay;
           
           stay = Console.ReadLine();
           
           Console.WriteLine("you are {0}",stay );
    
            if (stay.Equals(“exercise"));
            {
                Console.WriteLine("Well Done. You will get buff.");
            }
            
            
        }
    }
}
That is te exact code. I am getting an explci
0
That is the exact code and I am still getting an error
0
Sorry my bad, remove semicolones after the if statment (   if (stay.Equals(“exercise"))



