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.
var x = 10;
int y;
y = 20;
Related C# job interview questions
-
How can you find out what is the variable type?
C# Junior -
How can you declare a variable?
C# Junior -
What is a 'var' keyword in C# good for?
C# Junior -
What is a variable?
C# Junior -
What is the 'new' keyword used for in C#?
C# Junior