Equivallent to Console.ReadKey() in C#

I remember the code of C++ to pause the Console to show the output. Otherwise the Console exit with either a return type returned or its data type is a void.

system("pause"); // pauses the system, Windows OS only

Well, now that I have to move to C#, I don’t find those System commands. They were a bit handy. But since they’re not built-in, they can be developed in custom. Example code would be

public void pause() {
   Console.WriteLine("Press any key to continue...");
   Console.ReadKey();
}

public void main() {
   pause();
}

Now it would execute, it would be just the way C++ paused the Console. It would show the dialoge, and then would pause the Console. The return type is void, that’s why it won’t return anything in the Stream as output either.

Pretty simple it was!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s