How to use the IF Statement C#

All tutorials created in C# to be posted in here.
2 posts Page 1 of 1
Contributors
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

How to use the IF Statement C#
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...
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
smashapps
Coding Guru
Coding Guru
Posts: 961
Joined: Tue Apr 05, 2011 8:41 am

Re: How to use the IF Statement C#
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.
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
2 posts Page 1 of 1
Return to “C-Sharp Tutorials”