In C#, what does using a dollar sign do in Console.WriteLine [duplicate]
Asked Answered
E

2

5

thank you for looking at my question, to verify what i mean

Console.WriteLine($"Hello {variable}");

I am curious to the effect that the $ has on the output from Console.WriteLine

Eleen answered 23/7, 2016 at 5:25 Comment(1)
I will in the future, I'm new to programming in general so I was completely unaware of this.Eleen
F
14
Console.WriteLine($"Hello {variable}");

Is I think equal to:

Console.WriteLine(string.Format("Hello {0}", variable));

It just moves the parameter into the index position as if you were formatting it.

Firman answered 23/7, 2016 at 5:31 Comment(0)
I
6

It is a new feature to use in addition to string.Format

It's called Interpolated Strings

Intercostal answered 23/7, 2016 at 5:27 Comment(1)
$"<text> {<interpolated-expression> [,<field-width>] [<:format-string>] } <text> ..."Senhauser

© 2022 - 2024 — McMap. All rights reserved.