Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 691
TJ Corey Avatar asked Jul 23 '16 05:07

TJ Corey


People also ask

What does << mean in C?

<< is the left shift operator. It is shifting the number 1 to the left 0 bits, which is equivalent to the number 1 .

What does %d do in C?

In C programming language, %d and %i are format specifiers as where %d specifies the type of variable as decimal and %i specifies the type as integer. In usage terms, there is no difference in printf() function output while printing a number using %d or %i but using scanf the difference occurs.

What is && operator in C?

The && (logical AND) operator indicates whether both operands are true. If both operands have nonzero values, the result has the value 1 . Otherwise, the result has the value 0 . The type of the result is int . Both operands must have an arithmetic or pointer type.


2 Answers

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.

like image 151
topdog Avatar answered Oct 31 '22 06:10

topdog


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

It's called Interpolated Strings

like image 5
Thaina Yu Avatar answered Oct 31 '22 05:10

Thaina Yu