Writing Methods and Classes in LINQPad

LINQPad is a helpful tool for testing and learning LINQ snippets. Although it supports all LINQ  in C# 4.0 and Framework 4.0, it does have a querky syntax that you must implement in order to add your own classes and/or methods.

In short, to add your own classes and/or methods to LINQPad, you must:

  1. Create a New Query and choose “C# Statement(s)” for the LINQPad Language
  2. Position all of your LINQPad scripts at the top of the page
  3. After the very last LINQPad script, add a closing curly brace “}”
  4. After the closing curly brace that you added in step #3, you can add your classes and or methods as you would normally.
  5. When you finish writing all of your classes and/or methods, omit the very last closing curly brace. – Strange, but true.

Here’s an example LINQPad query that includes a Method and two Classes. Notice how the LINQPad query is positioned at the top of the page with an appended closing curly brace. Next, notice how the very last class (Pet) has omitted its closing curly brace.