✅ Beginner question about formatting

Hey all! I'm learning the basics and struggling a bit to understand why the second picture correctly displays the message. While trying to format the output text I also tried to do: - Console.WriteLine($"Celsius conversion: " + {celsius:F1} + " Celsius."); and it obv resulted in some kind of syntax error. Can someone help me understand why the bold example and the first picture's code didn't work? Also, prettty strange that the module didn't really explain the {celsius:F1} thing
No description
No description
3 Replies
Italian Raccoon
Italian RaccoonOP4w ago
I mean first pic just doesn't really have any type of formatting attempts so iI guess that's the reason for one to not work
Angius
Angius4w ago
Well, because the first example just concatenates the raw value as it is While the second one does, basically, a .ToString("F1") Which formats the Floating-point value to a string with 1 decimal place The second example uses string interpolation

Did you find this page helpful?