Hi,
How does the WriteLine() Method know to print to the console?
Is is using deferred execution behind the scenes in that an expression tree of some sort is being used?
Regards,
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Apr 3, 2011, 9:41 AM
In fact Console.WriteLine() is just a convenience method for the more long-winded Console.Out.WriteLine() where the Out property is a reference to the output stream.
It was introduced in .NET 1.0 and certainly doesn't use deferred execution or expression trees which were much later additions.
Sam HobbsPosted Apr 4, 2011, 12:15 PM
VulpesPosted Apr 4, 2011, 6:31 AM
However, we can still use the ReadFile() and WriteFile() functions whether the standard input and output has been redirected or not. If passed a console handle, these functions (in effect) treat the console buffer as though it were a file.
Sam HobbsPosted Apr 4, 2011, 12:43 AM
"ReadConsole and WriteConsole fail if used with a standard handle that has been redirected and is no longer a console handle."
....
"The functions do not return keyboard events involving the function keys or arrow keys. Input events generated by mouse, window, focus, or menu input are discarded."
....
if "line input mode is enabled" .... "do not return to the calling application until the ENTER key is pressed"
Just think about it. Streams only move forward; the console API is used to randomly move around the screen. The two are fundamentally incompatible.
VulpesPosted Apr 3, 2011, 6:03 PM
Sam HobbsPosted Apr 3, 2011, 4:02 PM
I had assumed that the .Net Console reads and writes could be redirected; is that incorrect? I thought that the Windows API console functions could not be redirected.
VulpesPosted Apr 3, 2011, 3:49 PM
All the Console API functions (see http://msdn.microsoft.com/en-us/library/ms682087(VS.85).aspx) can be P/Invoked from C# and work fine if you need any extra functionality, such as mouse support, which is not wrapped by the System.Console class.
Sam HobbsPosted Apr 3, 2011, 2:41 PM
The C++ language defines standard input and standard output devices, which are typically a console window. The concept of a console is the result of the time period when C++ was designed, in which dumb terminals were used with computers. I don't know the C# language has a similar definition but it probably does. I assume that the C# language defines the Console class to be an object that could be the equivalent of a dumb terminal, although I am sure they don't use the term dumb terminal. A Console is likely defined to be a text-only window.