相关疑难解决方法(0)

如何插入字符串?

我想在C#中做以下事情(来自Python背景):

strVar = "stack"
mystr  = "This is %soverflow" % (strVar)
Run Code Online (Sandbox Code Playgroud)

如何用字符串外的值替换字符串中的标记?

c# string string-interpolation

105
推荐指数
7
解决办法
5万
查看次数

VS 2015中字符串插值的最终格式是什么?

我不能让字符串插值工作.MS发现的最新消息是

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

然而所有这一切都表示,目前没有工作.有人知道字符串插值是否进入VS 2015?有没有关于它的文件?你举个例子吗?

例如,这些格式都不起作用(编辑):

int i = 42;
var s = "\{i}";  // correction after jon's answer: this works!
var s = $"{i}";  // compiler error
var s = "{{i}}"; // no interpolation
Run Code Online (Sandbox Code Playgroud)

编辑关于VS 2015 CTP 6(20.4.2015)

最终版本是

var s = $"{i}"
Run Code Online (Sandbox Code Playgroud)

目前的Resharper版本ReSharper 9.1.20150408.155143也支持

c# string-interpolation c#-6.0

34
推荐指数
2
解决办法
8533
查看次数

标签 统计

c# ×2

string-interpolation ×2

c#-6.0 ×1

string ×1