What is the final format for string interpolation in VS 2015?

落爺英雄遲暮 提交于 2019-11-27 14:34:34

Your first form did work in the VS2015 Preview:

int i = 42;
var s = "\{i}";

That compiled and ran for me. ReSharper complained, but that's a different matter.

For the final release of C#, it is:

var s = $"{i}";

String interpolation is making it to VS 2015. Its latest syntax (which wasn't ready for the preview, but made it into VS2015 CTP5) is this:

string s = $"{i}";

It also supports am IFormattable result using the FormattableString class:

IFormattable s = $"{i}";

The latest design documentation is here: String Interpolation for C# (v2)

You can check that online using the latest Roslyn version with http://tryroslyn.azurewebsites.net. Here's the specific example.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!