0

I am using the VS2013 on a windows 8.1 to learn Programming Windows from a book I bought, programming windows 6th edition. I am trying to use VS2013 to build and run the following cs code

class FirstProgram
{
    public static void Main()
    {
        System.Console.WriteLine("Hello, .NET Framework!");
    }
}

It compiles correctly according to the debug, but it takes me to a new window titled "FirstProgram.Window". Which, is the name of my program, but nothing displays on the screen.

Connor
  • 45
  • 8
  • you are using Console Application ? – Dhaval Patel Aug 08 '14 at 05:03
  • Try adding a `System.Console.Read();` after the `System.Console.WriteLine("Hello, .NET Framework!");` line. Its possible that the program exits immediately after the output is written in the console. – Chirag Bhatia - chirag64 Aug 08 '14 at 05:04
  • If you're using a WinForms/WPF application the console output (`System.Console.WriteLine()`) is redirected to the output window of VS. You can press `Ctrl + Alt + O` to open it. – webber2k6 Aug 08 '14 at 05:17

5 Answers5

0

That is because your Main method ends directly after Console.WriteLine, thus closing the console window. Add a call to Console.ReadKey() to make the window hang waiting for input.

Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321
0

The output actually gets written to that Window. Try adding a new line to your code

public static void Main()
{
Console.WriteLine("Hello, .NET Framework!");
Console.WriteLine("Press any key to exit.");
Console.Read();
}

Or, use Ctrl + F5 to start your console app.

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • That is what I am using to start it, but it takes me to a grey screen with no text on it whatsoever. – Connor Aug 08 '14 at 15:18
0

I suppose you created a windows form,If you just want to show something on the screen write.

System.Windows.Forms.MessageBox.Show("Your message");

Console.WriteLine will print output to Console window. If you are creating console application refer to other answers.

Nabeel Bape
  • 60
  • 1
  • 9
0

You can use Below menioned Code to see the Output

 System.Console.WriteLine("Hello, .NET Framework!");

 Debugger.Break();
Dhaval Patel
  • 7,471
  • 6
  • 37
  • 70
0

C#

CONSOLE APPLICATION

  1. try using Ctrl + F5 to run application!
  2. or simply add any of Console.Read(); or Console.ReadLine(); at the end of your code!

example:

class FirstProgram
{
    public static void Main()
    {
        System.Console.WriteLine("Hello, .NET Framework!");
        /* your code goes here! */
        Console.Read();
    }
}