Extension methods not working in subclasses?

Apparently extension methods don't work in subclasses, or is it just me?

private class Parent
{        
}

private class Child
{
}

public static class Extensions
{
    public static void Method(this Parent parent)
    {
    }
}

//Test code
var p = new Parent();
p.Method();            // <--- compiler like
var c = new Child();
c.Method();            // <--- compiler no like

UPDATE

There is a typo in this question (which I leave, so the rest makes sense) - I forgot to do Childinherit from Parent.

Be that as it may, my real problem was that I did not have the appropriate operator using.

(Unfortunately, I cannot delete, because there are too many answers when answering.)

+3
source share
1 answer

( LINQ IEnumerable<T>, List<T> .). , Child Parent .

+7

Source: https://habr.com/ru/post/1765788/


All Articles