简体   繁体   English

C#编译器找不到接口扩展方法?

[英]C# compiler can't find interface Extension Method?

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. 但编译器说,它找不到foo(),第一个参数是IA类型。 How can I fix it? 我该如何解决?

Have you marked your extension class as static as well? 您是否将扩展类标记为静态? ie 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(); } 
 } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM