Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何为IFormattableString赋值?($“hi{name}”在c#6.0新的IFormattablestring特性中)_C#_C# 6.0 - Fatal编程技术网

如何为IFormattableString赋值?($“hi{name}”在c#6.0新的IFormattablestring特性中)

如何为IFormattableString赋值?($“hi{name}”在c#6.0新的IFormattablestring特性中),c#,c#-6.0,C#,C# 6.0,如何为IFormattableString分配值 不可能按如下方式使用吗 string name = "Booley"; string template = "Hi mr. {name}, hope you enjoy the chicken!"; Console.WriteLine(template,name); 输出 Hi mr. Booley, hope you enjoy the chicken! 我知道如何实现这一点,但我很好奇为什么不能使用新的C#6.0特性来实现这一点。变量名

如何为IFormattableString分配值

不可能按如下方式使用吗

string name = "Booley";
string template = "Hi mr. {name}, hope you enjoy the chicken!";

Console.WriteLine(template,name);
输出

Hi mr. Booley, hope you enjoy the chicken!

我知道如何实现这一点,但我很好奇为什么不能使用新的C#6.0特性来实现这一点。变量名仅在编译时可用?

字符串前面缺少$。它应该是
stringtemplate=$“你好,{name}先生,希望你喜欢鸡肉!”

我不明白这个问题。您谈论的是
IFormattableString
,但在代码中没有使用它。你到底想做什么?这就是重点,我不想使用$,我想从文件中加载字符串。@hrein1000这个注释没有意义。您是否需要字符串插值(以
$
开头的字符串)。字符串插值是一种语言功能,由编译器实现,而不是格式化字符串的新语法。运行时在哪里可以找到从文件加载的字符串中指定的变量名?IL不存储变量名。