AllTheTimeWorld.com

csharp variablesAssigning Values to a Variable

Assigning Values to a Variable

Syntax of the assignment statement to give value to variable

Assigning Values to a Variable

Syntax of the assignment statement to give value to variable

Variables can be given a value using an assignment statement:

age=12;
answer='Y';
cost=5.25;

The variable that is getting a value is always on the left.

The statement below will give both num1 and num1 a value of 5.

num1=num2=5;

You can also get values from the form or from controls:

string title = this.Text;
bool ready = chkReady.Checked;
Color myColor = this.BackColor;