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.

Advertisements

One thought on “Writing Methods and Classes in LINQPad

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s