Page 1 of 1

How to use the IF Statement C#

Posted: Fri Mar 11, 2011 8:51 am
by MrAksel
Im just going to show you how to use the If statement in C#
'var' is a variable you will check against 'var2'
Code: Select all
if (var == var2) // Remember TWO = chars, else you will get an error
{
//Do something
}
else
{
//Do something else
}
Its that simple...

Re: How to use the IF Statement C#

Posted: Fri May 03, 2013 12:33 pm
by smashapps
I know this tutorial is old I was looking through the tutorials to see what hasn't been posted. People should understand the difference between using = and ==.

Firstly = is an assignment operator which means you're setting one value to another.

== is the equality operator (A comparison operator) which allows you check if a value is equal to another value hence why we use the equality operator in an if statement rather than an assignment operator.