-1

Why can't I use the dollar sign $ in Console.WriteLine()?
I know that I use it for using the C# code in {} but it doesn't work and I don't know why? My code is:

Console.WriteLine($"Name is : {}");

but Visual Studio gives me some error

Error 1 Unexpected character '$
Error 2 Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement

I use Visual Studio 2013, I have this problem in this version but in version 2019 I don't have this problem. How can I fix this problem?

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
Kian.Net
  • 7
  • 1
  • 3
    That string formatting shorthand became available in VS 2016. You're using quite an extremely old and deprecated VS version – Camilo Terevinto Oct 03 '21 at 08:59
  • This looks like a [XY problem](https://xyproblem.info/). – Julian Oct 03 '21 at 08:59
  • Yeah i think it's because I use the old version of visual studio – Kian.Net Oct 03 '21 at 09:01
  • 2
    I reopened this question. The linked duplicate asked "what is a $ string" -- the OP clearly understands what the feature is, but they are asking *why it doesn't work*, which was not answered there. – Jonathon Reinhart Oct 03 '21 at 09:04
  • You need support for C# 6 features in the tools you use. Once you have that, expect something like **error CS1733: Expected expression** because you leave the braces empty, `$"Name is : {}"`. – Jeppe Stig Nielsen Oct 03 '21 at 09:42

1 Answers1

4

A $-prefixed string is an interpolated string which was added to the language in C# v6.

Visual Studio 2013 supports C# v6, but only as an optional feature: How to enable C# 6.0 feature in Visual Studio 2013?

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328