Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
114 views
in Technique[技术] by (71.8m points)

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

I can't get string interpolation to work. Last news from MS I found was

http://blogs.msdn.com/b/csharpfaq/archive/2014/11/20/new-features-in-c-6.aspx

However all that is said there is not working. Anyone knows if string interpolation made it into VS 2015? Is there any documentation about it? Can one you give an example?

For instance, none of these formats work (edited):

int i = 42;
var s = "{i}";  // correction after jon's answer: this works!
var s = $"{i}";  // compiler error
var s = "{{i}}"; // no interpolation

edit about VS 2015 CTP 6 (20.4.2015 )

The final version is

var s = $"{i}"

also supported by the current Resharper version ReSharper 9.1.20150408.155143

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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}";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...