Write to C# Immediate window in 2005

How do we write to the immediate window from the code

window. Similar to "Debug.Print" in VB.

Thank you,

Paul



Answer this question

Write to C# Immediate window in 2005

  • Mark Stega

    Not Debug.WriteLine("X"); does nothing either. Here is

    the code I tested.

    private void button2_Click(object sender, EventArgs e)

    {

    StreamReader re = File.OpenText("c:\\MyFile.txt");

    string input = null;

    while ((input = re.ReadLine()) != null)

    {

    Debug.Print(input);

    Debug.Write(input);

    Debug.WriteLine(input);

    }

    re.Close();

    }


  • Melchior91598

    For a console app... try Console.WriteLine("Hello");

    For a windows form app... try MessageBox.Show("Hello");


  • Hansjoerg

    I want to write to the "Immediate Window" not

    to a "messagebox" or the "console window"

    Anyone know how

    Thanks


  • kabirbasha

    soli3d,

    Check to ensure that you're checking the IDE's Output tab is visible. The immediate window won't print anything sent via a Debug.Print however the debuggers Output pannel should show your output.

    To ensure you're in the Output panel of the IDE click on the Main Menu button 'View' and select Output (or hold 'control+w' down and press 'o' on the keyboard)

    Other information that will be in this window will also include the loading of resources and starting and ending of threads used by your application with addition to all of the compiler messages sent durring compilation. Assuming there is infact text in your MyFile.txt file, your Debug.Print calls should be writing here successfully.

    Good luck!

    -Jonathan



  • MJ Mullen

    Thanks All, I understand it's use, I just cannot get it to work. I tried

    using System.Diagnostics;

    Debug.Print ("testString");

    Nothing gets printed to debug window. Any idea


  • wilrodmo

    Jonathan, You're the man, works perfect.

    Thanks everyone,

    Paul


  • Siva M

    Debug.WriteLine("AnyString"); // is this working , and your compliation = Debug Mode


  • newtWales

    The Immediate window is used to debug and evaluate expressions, execute statements, print variable values, and so forth.

    like
    >Debug.Print varA
    // this is used to print the value of VarA

    check out the complete article here
    http://msdn2.microsoft.com/en-us/library/f177hahy.aspx



  • myemac

    In my case:

    Console.WriteLine( "Name:{0}, Address:{1}", my_dataReader["FirstName"], my_dataReader["Title"]);

    Debug.Write ("AAA");

    both print the string to Output window

    I think the trick is to use Output window instead of immediate window

    Cheers



  • Michael Luttmer

    never mind. I closed the project, rebooted, and now it is magically working.


  • Richard Taylor

    Hey,

    I've got a similar problem. The debug statements are showing on the output window for all my classes except one.

    I even put the stop point on one of them and when I ran the program, it moved the stop point down to the next executable line of code.

    like I said, my other classes have debug statements and they are working fine.

    here are two of the statements:

    System.Diagnostics.Debug.WriteLine(_localDirectory + _fileDirName);

    System.Diagnostics.Debug.WriteLine("test ");

    During run time, I can hover over the values and I get the tool tip that shows the values.

    Any ideas

    Thanks,

    Joanna.


  • Write to C# Immediate window in 2005