开发者

What is the "Console" in Console.WriteLine statements?

foreach(int i in array1)
{    
    Console.WriteLine(i);
}

What is "Console" in this c开发者_C百科ontext?


In this case, Console is old-school DOS, AKA "STDOUT" or "standard out".
See Creating Console Applications (Visual C#).


Console is a static class, a part of the .NET framework. The full name is System.Console.

The documentation is here: http://msdn.microsoft.com/en-us/library/system.console.aspx

It may represent the standard I/O channels, but has other functionality too.


This means that you are writing out the value of i to the console Window

Console.Writeln(i); 

Actually it should be:

Console.WriteLine(i);

Console WriteLine Method: http://msdn.microsoft.com/en-us/library/system.console.writeline.aspx

Console Class: http://msdn.microsoft.com/en-us/library/43zwz7ys.aspx


Console represents the standard input, output, and error streams for console applications. This class cannot be inherited.

The Console class provides basic support for applications that read characters from, and write characters to, the console. If the console does not exist, as in a Windows-based application, writes to the console are not displayed and no exception is raised.

Data from the console is read from the standard input stream; normal data to the console is written to the standard output stream; and error data to the console is written to the standard error output stream. These streams are automatically associated with the console when your application starts, and are presented to you as the In, Out, and Error properties.

Console.WriteLine(i); // will do the work of printing and enter into new line.
Console.Write(i); // will just print *without new line*

For further information, check the MSDN article for the Console Class.


If you are running this app in a command app (cmd.exe) that text will be printed to the screen. It won't be visible if you are running as a windows app.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜