If you haven't checked out LINQPad before it's probably high time. LINQPad is a cool little utility that was mainly created to allow you to test LINQ expressions and see them produce a result and output the results in a nice easy to visualize format. It's great for running LINQ Queries without having to fire up Visual Studio.
LINQPad does a great job at LINQ execution and visualization, but it has a lot more uses than just a LINQ query tool. It's basically a snippet editor that allows you to save snippets and more importantly, execute just about any code that you can write as an expression or single function block . You can execute both Expressions which is a single command that returns a result or a single block of commands or a Statement which is a block of commands in a single execution block (essentially what would amount to a method body).
It's awesome if you just want to very quickly verify how some .NET function or expression works without having to write a test, console output routine or change your code and run it with the debugger.
For example, just a minute ago I was having some issues with a Path.Combine() in an application where the two path components passed in would be a path and filename, except that the filename could also have a leading slash and it was returning what I thought are unexpected results. Here's what this looks like in LINQ Pad after I needed to do some quick experiments with various different combinations of files and paths:
You can see the unfortunate result in the first result line in the Results panel which produces \test.tmp instead of the expected combined path. Actually the behavior is correct - the combination of the two paths sees no common path to combine so it just uses the latter part. Still I expected the function to assume I wanted to combine two paths regardless of the leading slash. <shrug>
Anyway, using LINQPad it was a piece of cake to paste the line and execute it without even touching the code I was working on in Visual Studio. LINQPad uses a .Dump() extension method on object to display the content of just about any structure to text output. It'll dump simple values with .ToString() and complex structures in an easy to visual tabular display. For example, above I added an anonymous type to the result which is shown in the table in the results pane above.
The cool thing is that it works with any code. There's even an Advanced option on the Query menu that allows you to import assembly references and namespaces so you can test your own assemblies.
Of course LINQPad - as the name implies - also works with LINQ queries and does a wonderful job of displaying LINQ and LINQ to SQL results:
Output can be displayed both as a result table view, the raw SQL (from .ToString()) and a useful code conversion from the LINQ Expression syntax to LINQ command syntax using command chaining of the various LINQ extensions methods.
There's no installation - it's a single self contained EXE you can copy anywhere assuming you have .NET 3.5 installed.
If you haven't looked at LINQPad before - even if you're not using LINQ yet, be sure to check it out...This is one of those useful tools you just should always have around and "linqed" to a hotkey, in VS or as I do with SlickRun. It's a great way to quickly check out many things .NET.
I'll be at DevIntersection in Vegas this fall giving sessions on ASP.NET Core with Angular and Localization. Thinking of coming? Use discount code STRAHL and save a few bucks. If you do be sure to stop by and say hello!
Other Posts you might also like