© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3mo ago•
12 replies
nikatark

✅ can I add extensions for static classes

Hello, can static classes be extended?
Using the new syntax I can write static extensions for normal types like that:
var a = string.Hello();

static class Extensions
{
    extension(string s)
    {
        public static string Hello() => "Hello ";
    }
}
var a = string.Hello();

static class Extensions
{
    extension(string s)
    {
        public static string Hello() => "Hello ";
    }
}


But I cannot target static types for such additions, e.g.:
var a = Console.Hello();

static class Extensions
{
    extension(Console cs)
    {
        public static string Hello() => "Hello ";
    }
}
var a = Console.Hello();

static class Extensions
{
    extension(Console cs)
    {
        public static string Hello() => "Hello ";
    }
}


That errors with
'Console': static types cannot be used as parameters
'Console': static types cannot be used as parameters

Even though I don't think its a fundamentally different extension.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Static vs Non-Static classes [Answered]
C#CC# / help
4y ago
Static Classes without Implementation
C#CC# / help
2y ago
✅ ternary select between static classes
C#CC# / help
2y ago
Do static classes leak memory?
C#CC# / help
3y ago