11

PHP has a function called print_r() and var_dump() that will display all the contents of an item. It makes it very easy to figure out what things are.

Is there something like that in C#?

I know there is a Console.WriteLine("Hello"); in C#, but does this work in the MVC? Can I do some type of debug.trace() like flash does into a debug console while I run the application?

Steve
  • 213,761
  • 22
  • 232
  • 286
JREAM
  • 5,741
  • 11
  • 46
  • 84

1 Answers1

26
System.Diagnostics.Debug.WriteLine("blah");

and in order to show all variables in the object you would have to override its ToString() method or write a method which returns all the info you need from the object. i.e.

class Blah{

    string mol = "The meaning of life is";
    int a = 42;    

    public override string ToString()
    {
         return String.Format("{0} {1}", mol, a);
    }
}

System.Diagnostics.Debug.WriteLine(new Blah().ToString());

In short there is nothing in built but it can be done.

If you must print ALL the objects info without overriding or adding logic on a class by class level then you are in the realms of reflection to iterate the objects PropertInfo array

Paul Sullivan
  • 2,865
  • 2
  • 19
  • 25