Reading a Value from a Variable

Once you’ve assigned a value to a variable, you can read the value back.  You can use the variable name anywhere that a value of the appropriate type is expected.
1
2
3
4
5
6
7
8
// Assign value to int variable
int n = 5;
 
// Read value from variable n and use it in an expression
int result1 = n * 2;
 
string info = string.Format("n={0}, result1={1}", n.ToString(), result1.ToString());
Console.WriteLine(info);
968-001