I’m starting to learn C# after learning Python, Css, HTML and a little bit of Js.
I have this code:
// Variables
var name = "Bob";
var messages = "3";
var temperature ="34,4";
// Print First Part
Console.Write("Hello, ", name);
Console.Write("You have ", messages);
Console.Write("in your inbox. ");
//Print Part II
Console.Write("The temperature is ", temperature);
Console.Write("celsius.");
But for some reason the output is this:
Hello, You have in your inbox. The temperature is celsius.
It doesn’t print the var. I really know it’s a very basic question lol,where’s the error? Any help ?
Thanks y’all for your responses and patience, I’m sorry for my misunderstanding, I think I’m doing wrong in applying other Coding Languages Knowledge in some of the things which are new for me in C# in this case. I would take a look at all your answers, analyze them and learn from them of course. Again thanks, a lot and have a nice day. I’m gonna mark one of your answers as solutions even tough all are correct.
Thanks and have a nice day.
>Solution :
You can use string interpolation: start string with $ prefix: $"..." then print the text while inserting variables wrapping them in braces: {someValue}:
// Print First Part
Console.WriteLine($"Hello, {name}. You have {messages} in your inbox.");
// Print Second Part
Console.WriteLine($"The temperature is {temperature} celsius.");