简体   繁体   English

等效于C#中的换行符

[英]Equivalent to newline in c#

What would I place after my variable to make the Console.WriteLine ("You input Y") appear on a different line? 我将在变量之后放置什么以使Console.WriteLine ("You input Y")显示在另一行上? Here's the code: 这是代码:

static void Main()
    {
        Console.WriteLine("Welcome to my bool program!");
        Console.WriteLine("Input a NON capital y or n please.");

        char Y = Console.ReadKey().KeyChar;

        if (Y == 'y')
        {
            Console.WriteLine("You input Y");
        }
        else
        {
            if (Y == 'n')
            {
                Console.WriteLine("You input N");
            }
        }

        Console.WriteLine("Press enter to exit the program, Have a good day!");
        Console.ReadLine();
    }

Thanks! 谢谢!

You can use 您可以使用

Environment.NewLine

which is a string that acts... as a newline. 这是一个充当换行符的字符串。

Alternatively you can just use 或者,您可以只使用

Console.WriteLine()

with no parameters, if a single newline is all you want. 没有参数,如果只需要一个换行符。

Console.WriteLine();

没有任何参数。

Console.WriteLine("\\r\\nYou input Y");

the problem is since you are reading a key character it will perform output right after the input. 问题在于,由于您正在读取按键字符,因此它将在输入后立即执行输出。

console.writeline() will work as well console.writeline()也将正常工作

In line with the comments on the question, you can do this in both C# and C++ 与对问题的评论一致,您可以在C#和C ++中执行此操作

if(something)
{
    doThis();
}
else if(somethingElse)
{
    doSomethingElse();
}
else
{
    kickChuckNorrisInTheTeeth();
}

if/else if/else is all supported in C# and C++ if / else if / else在C#和C ++中都受支持

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM