Din*_*sMo 7 .net c# string-interpolation c#-6.0
我是编程的新手,我刚刚安装了Visual Studio 2017.我创建了这段代码(来自我正在学习的书),但这不能编译.我有字符串插值的问题,我得到错误:
意外的字符'$',
但我使用的是C#6.0,所以这应该不是问题?
static void Main(string[] args)
{
string comparison;
WriteLine("Enter the number:");
double var1 = ToDouble(ReadLine());
WriteLine("Enter another number :");
double var2 = ToDouble(ReadLine());
if (var1 < var2)
comparison = "less than";
else
{
if (var1 == var2)
comparison = "equal to";
else
comparison = "greater than";
}
WriteLine($ "The first number is {comparison} the second number");
ReadKey();
}
Run Code Online (Sandbox Code Playgroud)
Gil*_*een 11
这是一个非常小的问题:)删除空格后$:
WriteLine($"The first number is {comparison} the second number");
Run Code Online (Sandbox Code Playgroud)
查看文档下的正确结构:
$"<text> {<interpolated-expression> [,<field-width>] [:<format-string>] } <text> ..."
Run Code Online (Sandbox Code Playgroud)
我已经请求了一个编辑,说明在此之后必须没有间距$,现在它说明:
| 归档时间: |
|
| 查看次数: |
1114 次 |
| 最近记录: |