Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# compiler can't find interface Extension Method?

Tags:

c#

I have an interface:

public interface: IA { ... }

and I try to extend it into

class public A : IA {
    private static void foo(this IA a) {
        a.foo();
    }
}

but compiler says, that it can't find foo(), with first parameter of type IA. How can I fix it?

like image 309
Michael Avatar asked Jan 16 '23 10:01

Michael


1 Answers

Have you marked your extension class as static as well? i.e. The class with the extension method must be marked as static AND the extension method itself must also be static.

 public static class AExtensions : IA 
 {
     public static void foo(this IA a) { a.foo(); } 
 } 
like image 162
BlackSpy Avatar answered Jan 29 '23 05:01

BlackSpy