How can you assign a value to a variable in C#?

Experience Level: Junior
Tags: C#

Answer

To assign a value to a variable, use the operator '='. In the code below the value 10 will be assigned to the variable x and the value 20 will be assinged to the variable y. It's like in math. The value from the right hand side of the assignment operator '=' gets assigned to the left hand side of the assignment operator.

Example

var x = 10;

int y;
y = 20;

Comments

No Comments Yet.
Be the first to tell us what you think.
C# for beginners
C# for beginners

Are you learning C# ? Try our test we designed to help you progress faster.

Test yourself