什么是C#字符串的$修饰符

ste*_*n.s 4 .net c# string

这个问题听起来与此类似:

在C#中字符串前面的@是什么?

但我已经在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)

@还有额外的$.这是什么意思?

Kie*_*Chu 5

它是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)