String interpolation is indeed a feature of C # 6.0, but C # 6 is not limited to VS2015.
You can compile applications that use the features of C # 6.0 in VS2013 by targeting the Roslyn compiler platform through the Microsoft.Net.Compilers NuGet package.
My experience is that after installing this package, error messages during compilation may be a little misleading. If you have compilation errors that are not related to C # 6, you will be shown these error messages plus error messages regarding invalid syntax related to any C # 6 functions that you used, despite the fact that now you are targeting a compiler that supports them.
For example...
public class HomeController : Controller { public ActionResult Index() { ViewBag.Title = "Home Page"; var example = $"{ViewBag.Title}"; ImASyntaxErrorWhatAmIWheresMySemicolonLOL return View(); } }
will result in 4 compilation error messages:
Error 1 Unexpected '$' character
Error 2 Invalid expression term ''
Error 3; Expected,
Error 4; Expected,
The first 3 errors here relate to a line that uses line interpolation, only the last error ; expected ; expected is a problem. Delete the violation line right before we return the View , and the compilation errors of the interpolation line will disappear, and everything will be fine.
joelmdev Oct 16 '15 at 20:49 2015-10-16 20:49
source share