← All notes

C# extension methods and extension blocks

Answer: Extension members let you add methods to an existing type without subclassing, recompiling or modifying it. The classic form is a static method whose first parameter uses this; newer C# adds extension blocks. An extension block is a block in a non-nested, nongeneric, static class that contains extension members for a type or an instance of that type. (S1)

Classic extension method

public static class StringExtensions {
  public static int WordCount(this string s) =>
    s.Split(' ', StringSplitOptions.RemoveEmptyEntries).Length;
}

"Hello Extension Methods".WordCount(); // 3

Extension blocks

public static class NumericSequences {
  extension(IEnumerable<int> seq) {
    public IEnumerable<int> AddEach(int n) => seq.Select(x => x + n);
  }
}

Extension blocks can be generic, and individual members can add their own type parameters.

Rules

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Microsoft Learn (.NET docs), Extension members - C#, CC BY 4.0 (dotnet/docs); Microsoft Learn (.NET docs), Extension member declarations - C# reference, CC BY 4.0 (dotnet/docs).

Cite this

Permanent ID: iil:note:k7a6rrwq

iinventedlight. 2026. "C# extension methods and extension blocks." iinventedlight Library, iil:note:k7a6rrwq, version of 2026-11-04. https://iinventedlight.com/library/notes/csharp-extension-methods/. License: CC-BY-4.0.

@misc{iil_note_k7a6rrwq,
  author = {{iinventedlight}},
  title = {{C\# extension methods and extension blocks}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-04},
  url = {https://iinventedlight.com/library/notes/csharp-extension-methods/},
  note = {Permanent ID iil:note:k7a6rrwq. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/csharp-extension-methods.md.