C # 6.0 - Unexpected '$' character
I am new to programming and I just installed Visual Studio 2017. I created this code (from the book Iām studying), but this does not compile. I have a problem with string interpolation and I get an error:
Unexpected '$' character,
but I am using C # 6.0, so should this not be a problem?
static void Main(string[] args) { string comparison; WriteLine("Enter the number:"); double var1 = ToDouble(ReadLine()); WriteLine("Enter another number :"); double var2 = ToDouble(ReadLine()); if (var1 < var2) comparison = "less than"; else { if (var1 == var2) comparison = "equal to"; else comparison = "greater than"; } WriteLine($ "The first number is {comparison} the second number"); ReadKey(); } +7
Dinosmo
source share1 answer
This is a very small problem :) Remove the space after $ :
WriteLine($"The first number is {comparison} the second number"); See the correct structure in the documentation :
$"<text> {<interpolated-expression> [,<field-width>] [:<format-string>] } <text> ..." I asked for an edit explaining that there shouldn't be spaces after $ , and now it points out:
+11
Gilad green
source share