gargmanoj
gargmanoj

Reputation: 123

Dumping Linq expression output to Console.

I have a linq expression which returns a list of objects. I want to dump that output to console in a pretty tabular format.

is there a way this can be achieved?

Upvotes: 2

Views: 1755

Answers (1)

Sergey Berezovskiy
Sergey Berezovskiy

Reputation: 236268

I like to use JSON.NET for serializing objects to string (in pretty tabular format). I also like to create extension method Dump() which outputs serialized object to console:

public static void Dump(this object value)
{
     Console.WriteLine(JsonConvert.SerializeObject(value, Formatting.Indented));
}

Usage is simple:

items.Dump();

Upvotes: 5

Related Questions