C# Extension Members
Overview: What are extension members? Extension members allow you to define additional members for existing types without modifying their definitions. With them, you can add functionality to existing types you don’t have access to or don’t control, for example, built-in types or types from an API or commercial library.  Extension methods have been a feature […]
---
[Image: Dotnet logo]
Essential productivity kit for .NET and game developers
Follow
- Follow:
- Guide Guide
- RSS RSS
Get Tools
.NET Tools
C# Extension Members
[Image: Rachel Appel]
Rachel Appel
Overview: What are extension members?
Extension members allow you to define additional members for existing types without modifying their definitions. With them, you can add functionality to existing types you don’t have access to or don’t control, for example, built-in types or types from an API or commercial library.
Extension methods have been a feature of C# since version 3.0 in 2007, so the concept has been around for some time in .NET. However, traditional extension methods were just that – methods only. Extensions could not be created for properties, fields, or operators. You couldn’t create static extensions and they couldn’t easily participate in interfaces. However, new syntax in C# 14 allows both instance and static properties and methods, as well as operators.
Classic extension methods
Let’s quickly review what a classic extension method looks like. We’ll extend the DateTime structure to check the first Monday of any quarter. You might see code like this in manufacturing scenarios where production runs need to start on a specific day, such as the first Monday of a quarter. The code looks something like this:
`
public static DateTime FirstMondayOfQuarter(this DateTime dateTime, int quarter)
if (quarter is < 1 or > 4)
throw new ArgumentOutOfRangeException(nameof(quarter),
"Quarter must be between 1 and 4.");
var year = dateTime.Year;
var firstMonth = (quarter - 1) * 3 + 1;
var date = new DateTime(year, firstMonth, 1);
var offset = ((int)DayOfWeek.Monday - (int)date.DayOfWeek + 7) % 7;
return date.AddDays(offset);`
Notice that to make the extension method you must make the class and method static, and use the this keyword to indicate which type to extend. While the definition uses the static keyword, it’s not a static member.
Code to use this extension method looks like the following:
`
DateTime myDate = DateTime.Now;
for (var i = 1; i <= 4; i++)
Console.WriteLine(myDate.FirstMondayOfQuarter(i).ToShortDateString());`
Because it’s not a static method, you can’t just call DateTime.FirstMondayOfQuarter(2). Calling DateTime.Now (or any DateTime member) creates a new instance of a DateTime.
Extension members in C# 14
Use the new extension block inside a static class to define extensions. The extension block accepts the receiver type (the type you want to make an extension for), and optionally, a receiver parameter name for instance members. Adding the parameter name is recommended for clarity. Here’s the syntax:
`
extension(Type) { … } // plain extension block
extension(Type parameterName) { … } // extension block with a parameter name`
If we want to convert a classic extension method to a new extension member, we can use Rider. Rider has a handy intention action for this, just press Alt + Enter and choose Move to extension block:
[Image: Animated gif showing how to use Rider to upgrade a classic method that extends the DateTime struct to calculate the first Monday of a quarter to an extension member]
The code to use it doesn’t change. However, you can now call the code without having to create an instance first, like this:
Console.WriteLine(DateTime.Now.FirstMondayOfQuarter(i).ToShortDateString());
So you won’t need to change any calling code unless you want to.
To create an extension property, use an extension block like you would for any extension member. The rest of the code looks very natural like regular C# code.
`
public static class DateTimeExtensions
extension(DateTime date)
public bool IsWeekend => date.DayOfWeek is DayOfWeek.Saturday or DayOfWeek.Sunday;
// To use it:
if (DateTime.Today.IsWeekend)
// No work today, yay!`
Notice that in the extension block you define methods, properties, and other members without using the this parameter syntax for each member.
A goal of the C# team was to ensure that existing code doesn’t break, so then the syntax you use becomes a matter of style. There’s no need to change any of your existing extension methods, but Rider’s handy intention action makes it fast and easy to do so.
In Summary
Extension members are beneficial for several scenarios, including transforming helper methods into properties, organizing related extensions, incorporating static constants or factories into existing types, defining operators on external types, and making third-party APIs feel more integrated or native.
C# 14
- Share
Prev post dotInsights | February 2026
[Image: image description]
Discover more
[Image: dotInsights | February 2026]
dotInsights | February 2026
Did you know? C# allows digit separators (_) in numeric literals to make large numbers more readable, e.g., int num = 1_000_000; is valid and equals one million.
Welcome to dotInsights by JetBrains! This newsletter is the home for recent .NET and software development related information.
🔗…
[Image: Rachel Appel]
Rachel Appel
ReSharper and Rider 2025.3.2 Updates Out Now!
We’ve just released another update for ReSharper, Rider and the .NET tools version 2025.3. You can update to this version from inside those tools, using the Toolbox app or our website.
Let’s take a look at the latest updates.
Rider 2025.3.2
Agent Client Protocol (ACP) agent regi…
[Image: Sasha Ivanova]
Sasha Ivanova
Game Dev in 2025: Excerpts From the State of Game Development Report
As we approach the midpoint of the decade, game developers face an evolving landscape shaped by shifting job security, technology choices, platform strategies, and practical AI adoption. Our State of Game Development 2025 report reveals critical insights that provide a clearer picture of where the industry is heading.
[Image: Anna Ruban]
Anna Ruban
How We Made Variable Inspections 87 Times Faster for Unreal Engine in Rider
If you've ever expanded a complex Unreal Engine variable in Rider's debugger and had time to contemplate your life choices, this post is for you.
We've rewritten our expression evaluator, and the results are dramatic: Variable inspection is up to 87 times faster on warm runs and 16 times faster o…
[Image: Sasha Korepanov]
Sasha Korepanov
---
[Original source](https://blog.jetbrains.com/dotnet/2026/02/23/csharp-extension-members/)