这个问题听起来与此类似:
但我已经在C#中的字符串文字前面了解@ -character的含义.
但是现在我在一个例子中看到了这个:
var xml = $@"<toast>
<visual>
<binding template='ToastGeneric'>
<text>text</text>
</binding>
</visual>
<audio src='ms-winsoundevent:Notification.Looping.Alarm10' loop='true'/>
</toast>";
Run Code Online (Sandbox Code Playgroud)
@还有额外的$.这是什么意思?
它是interpolated stringC#6.0的新功能(https://msdn.microsoft.com/en-us/library/dn961160.aspx)
基本上,它取代string.Format("", params);了旧的C#版本
用法示例:
var str = "test";
var xml = $@"<toast>
<visual>
<binding template='ToastGeneric'>
<text>{str}</text>
</binding>
</visual>
<audio src='ms-winsoundevent:Notification.Looping.Alarm10' loop='true'/>
</toast>";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
661 次 |
| 最近记录: |