C#C
C#3w ago
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 ";
    }
}


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 ";
    }
}


That errors with 'Console': static types cannot be used as parameters
Even though I don't think its a fundamentally different extension.
Was this page helpful?