In C#, all executable code is contained in methods: only variable and class definitions can be outside - and variables need to be within a class.
code needs to be inside a method to be effective:
private float myFloat = 0.0f;
public void myMethod(float myParameter)
if (myParameter == 666.0f)
exists, it doesn't get executed when your code is running - it's a directive to the compiler to include or exclude code when you build the EXE file, not included in the EXE for later execution.
If you think of it like a car, when your buy a new car you select the options you want on it: black paint, 20" rims, and Cruise control for you! That provides directives to the car manufacturer when they build it:
#if (paint == Black) PaintIt(Black)
#elseif (paint = Red) PaintIt(Red)
That "fixes the options" on the car, they don't change from that point on and when delivered to you it will be black, sit higher, and have an extra stick on the steering column. You can use the cruise control at any time while you drive it, but unless you selected it with
when you bought the car, it doesn't exist and you can't use it.
in C# code, does the same thing: selects what code is comp0iled and stored into the EXE you run later.
is used to make decisions when the EXE file is running and you are playing the game, reading data from a DB, or shatever you app is trying to do.