An if
statement looks like this:
The “expression” part MUST be in parenthesis, they aren’t optional.
Also, the way we compare things to see if they are equal in C# uses the ==
operator. We only use =
to assign values to variables.
Also: if you want to compare a variable to a string, the contents of the string need to be in quotation marks. If you don’t use quotation marks, C# thinks you’re trying to refer to a variable named n
, not the string "n"
.
So the first if
statement needs to look like this:
Wow thank you! I’m writing this down
if-else documentation below
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/if-else
THANK YOU
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/strings/
Thanks!
the ifs should look something like if(yes==”n”)
Will do!
You didn’t use the dark theme.
I see in everyone’s responses they have the double == and in your pic it is just a single. Make sure you do the double. The single will assign the value to the variable. That bit me when I first started also.
Thanks! Will keep in mind
If ((example != “x”) || (example != “y”));
If statement with multiple if statements inside
It’s like saying If example is different than “y” or different than “x”
The comments are so friendly compared to stackoverflow. Love the reddit community. Just throwing that out there
C# devs
null reference exceptions