LINQPad extension methods
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Extension methods are especially useful in LINQPad because they let you add small reusable helpers to queries without building a full project first. The mechanics are the same as in normal C#: define a static method in a static class and mark the first parameter with this. The LINQPad-specific question is mostly about where to place those methods so your queries can see them.
Define an Extension Method in the Query
For one-off exploration, you can define the extension method directly in the same LINQPad query.
LINQPad compiles the whole query, so extension methods declared in the same script are immediately available for testing and iteration.
Make Reusable Extensions Available Everywhere
If you want the method in many queries, move it into LINQPad's shared extensions area instead of redefining it every time. A common workflow is to place reusable helpers in My Extensions, then reference them from later queries.
The main benefit is not syntax. It is reuse. Once the extension lives in your shared helper area, every future query can call it without copying boilerplate around.
Extension Methods Are Great for Query-Time Helpers
LINQPad is often used for quick inspection and transformation of data, so small helpers pay off quickly. For example, a string helper that normalizes whitespace:
That kind of method is ideal in LINQPad because it turns repetitive exploration logic into a readable verb.
Use Extensions to Keep Queries Readable
Without extension methods, query scripts often grow a pile of local helper calls that break the visual flow of the data transformation. Extensions keep the code close to how you think about the operation.
This reads naturally inside the query and keeps the data shaping logic reusable.
Know the Usual Rules Still Apply
LINQPad does not change the C# language rules for extension methods. The method still must live in a static class, still must be static itself, and still needs this on the first parameter.
If you forget one of those rules, LINQPad will not treat the method as an extension:
That method is callable, but not as numbers.Squares() because the first parameter is missing this.
Common Pitfalls
The biggest mistake is defining the method correctly but forgetting the static class requirement. In that case the code compiles only after changes, but the method is not usable the way you expect.
Another issue is putting too much application logic into LINQPad-only helpers. Extension methods are great for exploration, but if they become important production behavior, they should live in a normal shared library rather than only in a LINQPad environment.
People also sometimes overuse extension methods for operations that hide too much work. The best LINQPad helpers are small, obvious, and query-friendly.
Finally, if you move helpers into shared extensions, remember that changing them affects all future queries that rely on them. That is convenient, but it also means those helpers should stay stable and easy to understand.
Summary
- LINQPad extension methods are ordinary C# extension methods used inside LINQPad queries.
- For one-off work, define them in the query itself.
- For reuse, move them into LINQPad's shared extension area.
- Keep extension methods small and focused so queries stay readable.
- If a helper becomes core application logic, consider promoting it out of LINQPad into a real shared codebase.

