C# Feature - Extension members
Extension members
Section titled “Extension members”Extension members let you add methods, properties, and some operators to an existing type without modifying the original source type.
Introduced In
Section titled “Introduced In”This feature was introduced in C# 14. The official Microsoft Learn page for C# 14 is dated November 18, 2025 and states that C# 14 ships with .NET 10 and Visual Studio 2026.
Why This Feature Exists
Section titled “Why This Feature Exists”Before C# 14, extension methods used the this modifier on the first parameter of a static method. That syntax worked, but it was limited to methods. C# 14 adds extension blocks so related extension members can be grouped together and expressed more naturally.
What Changed in C# 14
Section titled “What Changed in C# 14”- Extension blocks can declare multiple extension members in one place.
- Extension properties are now supported.
- Static extension members can target the type itself, not only an instance.
- Existing
this-parameter extension methods still work and remain source-compatible.
Example
Section titled “Example”public static class StringExtensions{ extension(string text) { public int WordCount() => text.Split(' ', StringSplitOptions.RemoveEmptyEntries).Length; }}Usage:
string sentence = "C# extension members are easier to organize";Console.WriteLine(sentence.WordCount());When To Use It
Section titled “When To Use It”- Use extension members when you want to add focused helper behavior to types you do not own.
- Use extension blocks when several related extension members belong together.
- Prefer ordinary instance members when you control the original type and the behavior is core to that type.
Common Pitfalls
Section titled “Common Pitfalls”- Extension members never override real instance members of the target type.
- They only participate when the defining namespace is in scope.
- Adding too many broad extensions can make APIs harder to discover and reason about.