question 1 of 356,000
Ok, I have a problem. I am trying to switch over from C++ to C#...and i dont know what is going on. Im taking it one step at a time. First question: How do I pause the screen? In C++ it is simply " system("pause"); "...
Hmm, ok --
First of all, why would you want to 'pause' the screen in this way? To see output? If so, you can always run your console app through the terminal (go into Run, type cmd and navigate to the appropriate directory....)
However, if you really want to 'pause', you could always do the equivalent of a cin call... Console.ReadLine(); ...or some other equivalent. Personally I don't like the idea of artificially stalling the execution of your program like this. There's a number of other ways to get output etc so I guess the final word is consider why you're doing this in the first place?
[EDIT] Just for references sake, MSDN uses Console.ReadLine() -- check out this on the MSDN and see how they end their program. Just because MS shows you the way doesn't mean it's a good idea though ;)
~Shiny.
[Edited by - Shiny on April 30, 2006 2:51:49 AM]
First of all, why would you want to 'pause' the screen in this way? To see output? If so, you can always run your console app through the terminal (go into Run, type cmd and navigate to the appropriate directory....)
However, if you really want to 'pause', you could always do the equivalent of a cin call... Console.ReadLine(); ...or some other equivalent. Personally I don't like the idea of artificially stalling the execution of your program like this. There's a number of other ways to get output etc so I guess the final word is consider why you're doing this in the first place?
[EDIT] Just for references sake, MSDN uses Console.ReadLine() -- check out this on the MSDN and see how they end their program. Just because MS shows you the way doesn't mean it's a good idea though ;)
~Shiny.
[Edited by - Shiny on April 30, 2006 2:51:49 AM]
I use "getch()" from <conio.h> for a simple pause.
There are many other ways, such as loops and what not, that will have the same effect.
There are many other ways, such as loops and what not, that will have the same effect.
You have to pinvoke this C function into your C# application. Luckily, this process is very easy. There are a few steps:
1) Insert System.Runtime.InteropServices to your using clauses.
2) Insert this line in your class (usually in the first few lines)
[DllImport("msvcrt.dll")]
static extern bool system(string str);
3) In that same class, simply write this:
system("pause");
Hope that helps!
1) Insert System.Runtime.InteropServices to your using clauses.
2) Insert this line in your class (usually in the first few lines)
[DllImport("msvcrt.dll")]
static extern bool system(string str);
3) In that same class, simply write this:
system("pause");
Hope that helps!
This is absurd.
System("PAUSE") is a nasty and unnecessary icky. C# for console now like the new? Run from console, console stays and no closure.
System("PAUSE") is a nasty and unnecessary icky. C# for console now like the new? Run from console, console stays and no closure.
Are you afraid of a few milliseconds loss in a console application? Are you afraid of portability loss when you're obviously targeting the Windows operating system with C#? For my apps, Console.ReadLine() does enough for a quick solution.
Quote:Original post by Anonymous Poster
Are you afraid of a few milliseconds loss in a console application? Are you afraid of portability loss when you're obviously targeting the Windows operating system with C#? For my apps, Console.ReadLine() does enough for a quick solution.
Are you afraid of logging in?
[edit] And by the way, the "right" way of going about it (if you're too lazy to open up a console window), is to go to Debug->Start Without Debugging.
jfl.
Quote:Original post by jflangloisQuote:Original post by Anonymous Poster
Are you afraid of a few milliseconds loss in a console application? Are you afraid of portability loss when you're obviously targeting the Windows operating system with C#? For my apps, Console.ReadLine() does enough for a quick solution.
Are you afraid of logging in?
[edit] And by the way, the "right" way of going about it (if you're too lazy to open up a console window), is to go to Debug->Start Without Debugging.
jfl.
nice... lol.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement