Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C# Console.Write(" ", var);

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading