如何在文本中添加 +string?
How do I add +string within a text?
我想知道如何在 Console.WriteLine / Console.Write 中添加 [+行]。
例如:
string line;
Console.WriteLine("Enter one or more lines of text (press 'gg' to exit):");
do
{
Console.Write(" ");
line = Console.ReadLine();
if (line != "b")
Console.WriteLine(" Sorry, you wrote **???**, which is wrong. \n Try again." +line);
else
Console.WriteLine("u rock");
}
while ( line != "gg") ;
我想在句子中间加[+line],也就是问号所在的位置。
我该怎么做?
String interpolation 是您最好的选择(假设您使用的是 C# 6 或更高版本)。记住字符串开头的$:
Console.WriteLine($"Sorry, you wrote {line}, which is wrong. \n Try again.");
你也可以用来分隔加在一起的字符串,尽管这样有点笨拙:
Console.WriteLine("Sorry, you wrote " + line + ", which is wrong. \n Try again.");
我想知道如何在 Console.WriteLine / Console.Write 中添加 [+行]。
例如:
string line;
Console.WriteLine("Enter one or more lines of text (press 'gg' to exit):");
do
{
Console.Write(" ");
line = Console.ReadLine();
if (line != "b")
Console.WriteLine(" Sorry, you wrote **???**, which is wrong. \n Try again." +line);
else
Console.WriteLine("u rock");
}
while ( line != "gg") ;
我想在句子中间加[+line],也就是问号所在的位置。 我该怎么做?
String interpolation 是您最好的选择(假设您使用的是 C# 6 或更高版本)。记住字符串开头的$:
Console.WriteLine($"Sorry, you wrote {line}, which is wrong. \n Try again.");
你也可以用来分隔加在一起的字符串,尽管这样有点笨拙:
Console.WriteLine("Sorry, you wrote " + line + ", which is wrong. \n Try again.");