0
Can you make if statement based on a string for example: you have a String named "string1" and you want to test if the person got the text right or aomethibg like that
3 Réponses
+ 1
When "==" is used with objects, it checks whether the two or more objects being compared point at the same location in memory whereas equals(), compareTo() methods can be used to check whether the user has entered the correct details(string content).
+ 1
Officially, you should use the methods of System.StringComparison library and avoid using operators like "==" when comparing strings.
You can find examples of all kinds of operations you may need to compare strings in MSDN guide pages here:
> https://msdn.microsoft.com/en-us/library/cc165449.aspx
- 3
Yes you can. A program using this would look something like this:
String string1 = Console.ReadLine ();
if (string1 == "correct"){
Console.WriteLine ("Good Job!");
}
else {
Console.WriteLine ("Wrong!");
}