system("pause") in C#? (warning: noob question)
Hi guys!
First of all: I am totally new to the laguage C# - just learning the basics right now. I have some experience with C and C++ though. I just typed a simple program and compiled it, but it's hard to tell whether it's working or not, as the program closes immediately after launch. Is there some kind of pause function that can be used to delay shutdown of the program until the user presses a key? (like the one in C called system("pause"))
This is a good answer,isnt it?
If there is no alternative in C#,we can use System("pause") provided in msvcrt.dll,maybe it is not the best or the easiest way to do that,but we can learn from it,as we will know if we want to use those system calls in a C/C++ program,we can import msvcrt.dll :)
I am also a beginner at C#,and I reached here with google when I searched answers to my question,I think dxfoo is helpful to us,isnt he?
Quote:
Originally Posted by
dxfoo
You can interop it with msvcrt.dll, I believe. Ah, here's my old reply to the question:
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! It's not the best solution in C# to go about the problem, but hey, it's a solution.