LinqPad Dump Extension Method

tips & tricks

I like LINQPad for prototyping C# applications and trying out short snippets. In many scenarios I have to see the output of what I’m trying out. I used to treat my snippets as they if they were small console applications and I used to use Console.WriteLine() statements to display the output.

Not anymore! In a tech video on YouTube I saw this option and loved it:

In LinqPad, there’s a generic extension method called Dump(). It writes the output to the console. Exactly as Console.WriteLine but in a much more concise way.

For example:

var nums = new[] { 1, 2, 3, 4, 5, 6 };
var sum = nums.Aggregate((a,b) => a + b);

This displays 21 and it can be shortened with Dump method

var nums = new[] { 1, 2, 3, 4, 5, 6 };
nums.Aggregate((a,b) => a + b).Dump();

It shows the same result but in a shorter way.