c#中的"$"关键字有什么用 - web api

ash*_*eli 1 c#

HttpResponseMessage response = await client.PutAsJsonAsync($"api/products/{product.Id}", product);
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,我一直在使用$关键字,但我没有这个关键字的意义.我在谷歌搜索,但没有找到正确的答案.我认为这可能是重复但即使在stackexchange中也找不到相关答案.

提前致谢

Ser*_*kiy 8

它是一个插值字符串 --C#6的新特性,它基本上只是String.Format的语法糖(编译器将插值字符串转换为String.Format调用).你的字符串相当于

String.Format("api/products/{0}", product.Id)
Run Code Online (Sandbox Code Playgroud)