I am making a desktop application and I want to display the value of a variable on the screen inside the quotes this is my code
static void Main(string[] args)
{
int casa = 16;
Console.WriteLine("variable {{casa}}");
Console.ReadKey();
}
It prints casa
no 16
, it can be done by adding and the name of the variable but I want it inside the quotes, could it be done???
There are two ways to display the value of the variable:
Placing the variable after the operator
+
, outside the""
1)
Console.WriteLine("variable" + casa);
Or this second option is only available for C# >= 6.0 . Placing the symbol
$
after the start parenthesis and placing the variable name{}
inside the""
:two
Console.WriteLine($"variable {casa}");
All the best.
Having several options, the two most common, would be,
Concatenate
Or also, you could build a string with String.Format , but it would apply, perhaps, to more particular situations
As I said before, you have an infinite number of ways to do what you are looking for, it would be a matter of finding which one is the most comfortable for you.
Cheers