Console.WriteLine("Enter a Number:");
double firstNumber = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter another Number:");
double secondNumber = Convert.ToDouble(Console.ReadLine());
string Comparison;
if (firstNumber > secondNumber)
Comparison = "more than";
else
{
if (firstNumber < secondNumber)
Comparison = "less than";
else
Comparison = "equal to";
}
Console.WriteLine($"the first Number is {Comparison } than the second Number.");
Console.ReadLine();
代码的倒二语句中$的含义,以及Comparison为什么要加花括号?
Console.WriteLine($"the first Number is {Comparison } than the second Number.");
这是C# 2015新的语法,相当于
Console.WriteLine("the first Number is {0} than the second Number.", Comparison);