Console.Read()和Console.ReadLine()之间的区别是什么 [英] What is the difference between Console.Read() and Console.ReadLine()

查看:142
本文介绍了Console.Read()和Console.ReadLine()之间的区别是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家



Console.Read()和Console.ReadLine()之间有什么区别。现在我对许多答案感到困惑。任何人都可以为此提供代码示例,这对我来说很清楚这个概念。



帮助我。我在很多采访中都面对这个问题。直到现在我找不到正确的答案。

解决方案

嗨Vijay,

这会让你清楚我猜。



  class 计划
{
static void Main( string [] args)
{
// 将指定的字符串值写入标准输出流(控制台窗口)
Console.Write( All);
Console.Write( );
Console.Write( well);
// 输出
/ / 一切都很好


// 写入指定的字符串值,后跟当前行终止符,
// 到标准输出流。 (控制台窗口)
Console.WriteLine( All);
Console.WriteLine( );
Console.WriteLine( well);
// 输出
/ * 所有
*是
* well
* /


Console.Write( test + Environment.NewLine); // 1)显式添加行终止符
Console.WriteLine( test); // 2)隐式附加行终止符。 //(1& 2)都相同。

Console.ReadLine();

}
}


Read(),ReadLine()和ReadKey()基本上都是静态方法,它们是来自Console类。这就是我们使用这些方法的原因:



Console.Read();

Console.Readline();

Console.ReadKey();



现在让我们看看所有这些方法有什么不同:



Console.Read(): - 方法接受String并返回字符串。



Console.ReadLine(): - 方法接受String但是返回整数。



最后......



Console.ReadKey(): - 方法接受性格也回归人物。



这就是为什么我们大多使用Console.ReadKey()方法,从输出窗口返回源代码。



因为当我们只按下字符时我们直接来源代码。如果您将使用Console.Read()和Console.ReadLine方法,那么您需要按Enter键,返回源代码而不是任何字符。


< blockquote> Console.Read()只读取标准输入中的下一个字符,Console.ReadLine()从标准输入流中读取下一行字符。



查看这篇文章

http://stackoverflow.com / questions / 6825943 / console-read-and-console-readline 之间的差异[ ^ ]

http://onlydifferencefaqs.blogspot.com/2012/08/difference-between-readreadline-and.html [ ^ ]


Hi Experts

What is the difference between Console.Read() and Console.ReadLine(). Now i am confused with many answers. Can anyone give code example for this, which would great for me to clearly understand the concept.

Help me. I face this question in many interviews. Till now i did not find the correct answer.

解决方案

Hi Vijay,
this will make you clear i guess.

class Program
    {
        static void Main(string[] args)
        {
            //Writes the specified string value to the standard output stream (console window)
            Console.Write("All");
            Console.Write(" is");
            Console.Write(" well");
           // output
           // All is well


             //Writes the specified string value, followed by the current line terminator,
            //     to the standard output stream. (console window)
            Console.WriteLine("All");
            Console.WriteLine(" is");
            Console.WriteLine(" well");
            // output
            /*All
             * is
             * well
             */

            Console.Write("test" + Environment.NewLine); // 1) appended a line terminator explicitly
            Console.WriteLine("test"); //2) appends a line terminator implicitly. // (1 & 2) both are same.

            Console.ReadLine();

        }
    }


Read(), ReadLine() and ReadKey() are basically static methods, and they comes under the Console class. That's why we use these methods like:

Console.Read();
Console.Readline();
Console.ReadKey();

Now Lets see what is the differences in all these methods:

Console.Read():-- method accept the String and return the string as well.

Console.ReadLine():--method accept the String but return Integer.

Finally...

Console.ReadKey():--method accept the Character and also return Character.

That's why we mostly use the Console.ReadKey() method, for come back to source code from output window .

Because when we only press the character we directly come on source code. If you will use the Console.Read() and Console.ReadLine method then
you need to press Enter, come back to the source code rather then any character.


Console.Read() reads only the next character from standard input, and Console.ReadLine() reads the next line of characters from the standard input stream.

check this article
http://stackoverflow.com/questions/6825943/difference-between-console-read-and-console-readline[^]
http://onlydifferencefaqs.blogspot.com/2012/08/difference-between-readreadline-and.html[^]


这篇关于Console.Read()和Console.ReadLine()之间的区别是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆