20

Linqpad's souped-up Console.WriteLine is awesome. However, how can I do a standard Console.WriteLine of an object?

Colonel Panic
  • 132,665
  • 89
  • 401
  • 465

4 Answers4

27

Debug.WriteLine will also do the trick.

Joe Albahari
  • 30,118
  • 7
  • 80
  • 91
13

Huh, obvious now - put in an explicit ToString

Console.WriteLine(x.ToString());
Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
0

You can also add these methods to your "MyExtensions" file in the "My Queries" pane. This way you can use .DumpToString instead of .Dump. Maybe they should be renamed DumpDebug ...

// Write custom extension methods here. They will be available to all queries.
public static void DumpToString<T>(this IEnumerable<T> list)
{
    list.ToList().ForEach(x => Debug.WriteLine(x));
}

public static void DumpToString(this object o)
{
    Debug.WriteLine(o);
}

public static void DumpToString(this string o)
{
    Debug.WriteLine(o);
}
Derek
  • 7,615
  • 5
  • 33
  • 58
-1

You can also do

x.Dump();

Which will use the LinqPad API to pretty format the output.

Ryan Vice
  • 2,133
  • 3
  • 23
  • 33