小编pau*_*ljz的帖子

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#6.0中有什么作用?

在MVC 6源代码中,我看到一些代码行,其中包含带有$符号的字符串.

正如我之前从未见过的那样,我认为它是C#6.0中的新功能.我不确定.(我希望我是对的,否则我会感到震惊,因为我从来没有碰过它.

它就像:

var path = $"'{pathRelative}'";
Run Code Online (Sandbox Code Playgroud)

c# string-interpolation c#-6.0

10
推荐指数
1
解决办法
601
查看次数

Nodejs异步数据库功能需要同步应答

我是nodejs的新手,我正在编写一些代码,需要查询我的MySQL数据库并从给定的user_id返回一个用户名.我一直在读你所有的功能应该是异步的.在这种情况下,理想情况下我希望服务器能够在进行此查询时响应其他事件请求.但是,它不是一个特别大的查询,只返回一个值.也许我应该让它同步?(如果这是你的答案,改变它的示例代码会很棒)无论如何,这是我的功能.它在最后一行"return current_username;"附近发出错误 因为当前current_username未定义.有什么建议?

function get_current_username(current_user_id) {
    console.log(' | Entered get_current_username');
    sqlq = 'SELECT username FROM users WHERE id = ' + current_user_id;
    connection.query(sqlq, function(err, rows, fields) {
      if (err) throw err;
      var current_username = rows[0].username;
      console.log(' | the current_username =' + current_username);        
    });

return current_username;
Run Code Online (Sandbox Code Playgroud)

}

javascript asynchronous node.js

3
推荐指数
1
解决办法
2233
查看次数