Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unrecognized Escape Sequence C# 6 String Interpolation [duplicate]

According to New Features in C# 6, you should be able to declare strings as such:

var name = "world";
WriteLine("hello, \{name}");

For the output:

hello, world

I have created a new Console application, set the Target Framework to .NET Framework 4.6, and I am getting the error "Unrecognized Escape Sequence"

I am using Visual Studio Ultimate 2015 CTP Version 14.0.22512.0 DP

like image 910
Tom Avatar asked Feb 16 '15 15:02

Tom


People also ask

How do you fix an invalid escape character in a string?

Resolving The Problem Regex r = new Regex("\(HelloWorld\)"); which generates the Invalid escape sequence error. To re-iterate, the backslash character can be used as an escape sequence for a regular expression in a recognition property or a verification point.


1 Answers

The string interpolation convention changed. It is now using the "$" operator:

var name = "world";
WriteLine($"hello, {name}");
like image 199
Yuval Itzchakov Avatar answered Oct 13 '22 01:10

Yuval Itzchakov