1

I've been doing some beginner-level C# lately and I love the new Visual Studio and all, but is it possible to make my program output (when using Console, for example) appear on the little text area where errors are reported rather than a separate command line interface? In Eclipse and NetBeans, this is possible with Java.

I'm not particularly a fan of the CLI appearing every time I want to test a new line. I wonder if there is an option to have the output appear on the bottom of the same window like in NetBeans.

Fiery Phoenix
  • 1,156
  • 2
  • 16
  • 30

3 Answers3

2

This is rather a workaround, as I'm unaware of of a setting in visual studio to achieve this, but you could replace (or write a method which does both) Console.WriteLine with Debug.WriteLine.

Simon
  • 428
  • 5
  • 19
  • 1
    You can also use Trace.WriteLine if you want to see these messages when application is running in non-debug mode. – alex Apr 23 '13 at 20:36
1

No, writing a console program will always allocate a new window when using Visual Studio. However, you can display messages in the output window, take a look at Debug.WriteLine.

If I have a lot of messages to output, I will usually write a small utility method.

using System;
using System.Diagnostics;

class Program {
    static void Main() {
        WriteLine("Hello");
        WriteLine("The number is {0}", 42);
    }

    static void WriteLine(string format, params object[] args) {
        string message = String.Format(format, args);
        Console.WriteLine(message);
        Debug.WriteLine(message);
    }
}
Joshua
  • 8,112
  • 3
  • 35
  • 40
  • Hm, not quite as convenient as I'd hoped. But as long as it works, I guess. Thanks for your answer! +1 – Fiery Phoenix Apr 23 '13 at 20:45
  • I agree, it is quite inconvenient, but I think I can guess why they wouldn't allow you to do that. It wouldn't be able to capture any input (as the output window is read only) and what would happen if you called Console.SetCursorPosition(0, 0)? I'd hate to think about that one. – Joshua Apr 23 '13 at 21:03
0

This has been answered pretty well in another StackOverflow question. Here's the link to it: redirect-console-to-visual-studio-debug-output-window-in-app-config

Community
  • 1
  • 1
DevOhrion
  • 318
  • 1
  • 8