I write a class in C# and I want to display in console. But i can't display it.
My program doesn't have any errors, which means the program runs it but i can't see a result :(
Please help me regarding this problem.
I write a class in C# and I want to display in console. But i can't display it.
My program doesn't have any errors, which means the program runs it but i can't see a result :(
Please help me regarding this problem.
You can use Console.WriteLine(Object) to print the output, and Console.Read() to wait for user input.
Console.WriteLine("Hello world");
Console.WriteLine("Press any key to exit.");
Console.Read();
Without Console.Read, sometimes output just comes, and program exits in a flash. So Output cannot be seen/verified easily.
No Problem, I get what you are asking...
In regards to Microsoft Visual Studio 2010
Write Console.WriteLine("Where are you console?");
somewhere in your code - make sure you will definitely see it..
Press Debug button (or the play button)
In the Microsoft Visual Studio, Go to Debug -> Windows -> Output
A small 'Output' Windows should pop up and you can see your console write statements! - Obviously you gotta run the code and it will appear.
Hope it helps!
Press CTRL+F5 to see your output. This will wait the console screen until you press any key.
Your main structure must be in "Windows Form" architecture. So, try to attach parent (base) process, such as:
namespace MyWinFormsApp
{
static class Program
{
[DllImport("kernel32.dll")]
static extern bool AttachConsole(int dwProcessId);
private const int ATTACH_PARENT_PROCESS = -1;
[STAThread]
static void Main(string[] args)
{
if (Environment.UserInteractive) // on Console..
{
// redirect console output to parent process;
// must be before any calls to Console.WriteLine()
AttachConsole(ATTACH_PARENT_PROCESS);
// to demonstrate where the console output is going
int argCount = args == null ? 0 : args.Length;
Console.WriteLine("nYou specified {0} arguments:", argCount);
for (int i = 0; i < argCount; i++)
{
Console.WriteLine(" {0}", args[i]);
}
}
else
{
// launch the WinForms application like normal
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
}
(or write a console app from scratch)