Sacred Wizard
Sacred Wizard

Reputation: 3

Visual Studio2012 Output text

I wrote the following code in visual studio 2012:

using System;
class Example
{
    static void main()
    {
        int x = 100;
        Console.WriteLine("X Contains:" + x);
        int y = x / 2;
        Console.WriteLine("y contains");
        Console.WriteLine(y);
        Console.WriteLine("A Sample C# Program");
    }
}

There were no errors, but the output window was empty. It did not print anything. What should I do so that I get the text displayed?

Upvotes: 0

Views: 86

Answers (3)

HichemSeeSharp
HichemSeeSharp

Reputation: 3318

Your are writing to dos-console and expecting VS Output window to show written things. With your current code You shoud run that in Console Application project. it would open the Dos-command console an executes your commands on it.

Event if you are in console application project, you will see console flashes and then disappears.

Add Console.ReadLine(); after Console.WriteLine("A Sample C# Program");. this holds the console open.

Upvotes: 1

Mohamed E
Mohamed E

Reputation: 1

This code is work good try it. You Should play by click(ctrl+F5) IF you play With "F5" it will terminate immediately.

namespace ConsoleApplication1{

class Program
{
    static void Main(string[] args)
    {


        int x = 100;
        Console.WriteLine("X Contains:" + x);
        int y = x / 2;
        Console.WriteLine("y contains");
        Console.WriteLine(y);
        Console.WriteLine("A Sample C# Program");


    }
}

}

Upvotes: 0

Jarek Kardas
Jarek Kardas

Reputation: 8455

Console prints to the console (add Console.ReadLine() at the end so it doesn't terminate immediately). To print to output use Trace.WriteLine() or Debug.WriteLine()

Upvotes: 2

Related Questions