Declaring and initializing variables with C#!

The Following page will teach you all about variables.

Boolean

A boolean can only store 2 values. The values are true and false.

And Example - If you have a gun in a video game, the gun shooting is true or false.

You must first declare a virable before using it. This reserves the memory needed to store you

variables later on. The Code Is

Boolean blnVar;

You must then initialize the variable when using it for your first time. Here is the code.

blnVar = true;

Integers

Whenever counting, and or keeping track of an item you use the integer variable type.

dont use an integer if you need a decimal result.

How to Declare A Integer

Int32 intVar;

How to initialize A Integer

intVar = Number Here;

intVar = 15;

Floating Point

If you need a decimal or fraction result, you use somthing called Floating Point. The most

Common is called Double.

How to Declare a decimal Variable

Double dblVar;

How to initialize a decimal Variable

dblVar = 301.235;

Strings

If you need to use a word variable instead of a # variable, you use a String

A String can be any letter, any number, and also and puncuation.

Declaring a string Variable

String strVar;

Initializing a string Variable

strVar = "PPrimer";

If you want to declare and initialize at the same time use this code

String strVar = "PPrimer";

Now you know all about declareing and initializeing variables!

Click Me to go back to the main page!