Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

ExtensionMethodExamples - C# Extension Methods for Augmenting Existing Types

YouTube Blog Newsletter All Links LinkedIn

This .NET 8.0 console application demonstrates how to create and use C# extension methods to add new functionality to existing types without modifying their source code or using inheritance. The project shows how to extend HttpContext from ASP.NET Core with a GetBaseUrl() extension method that constructs the base URL from a request's scheme, host, and path base.

The example illustrates both calling the extension method as an instance method using the natural dot-notation syntax and calling it as a static method directly, demonstrating that extension methods are syntactic sugar over static method calls. This is a focused, minimal example that clearly shows the core concept of extension methods in C#.

Getting Started

Prerequisites

  • .NET 8.0 SDK or later

Running the Project

cd ExtensionMethodExamples
dotnet run

Related Resources

Blog Articles

Newsletter

If you found this useful and you want to learn more about C#, .NET, and software engineering, subscribe to the free Dev Leader Weekly newsletter:

Subscribe to Dev Leader Weekly

Connect with Dev Leader


BrandGhost

Powered by BrandGhost 👻