【发布时间】:2017-09-27 09:20:08
【问题描述】:
我是编程新手,我刚刚安装了 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();
}
【问题讨论】:
-
尽管这只是一个间距问题,但我不同意它因此而被搁置。这导致了一个编译错误,起初看起来很奇怪,因为间距在 C# 的许多部分都不是问题
标签: c# .net c#-6.0 string-interpolation