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

22nd Apr 2020, 4:20 AM
dave hazz
dave hazz - avatar
6 Respuestas
+ 1
Yeah replace your if statment with this: If (YourName.Equals(“Mike”));
22nd Apr 2020, 4:42 AM
Asad
0
YourName.equals(“Mike”) will compare string words
22nd Apr 2020, 4:32 AM
Asad
0
This will go inside the if bracket?
22nd Apr 2020, 4:35 AM
dave hazz
dave hazz - avatar
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
22nd Apr 2020, 4:54 AM
dave hazz
dave hazz - avatar
0
That is the exact code and I am still getting an error
22nd Apr 2020, 4:55 AM
dave hazz
dave hazz - avatar
0
Sorry my bad, remove semicolones after the if statment ( if (stay.Equals(“exercise"))
22nd Apr 2020, 5:18 AM
Asad