Java 函式式介面在 C# 中的等價形式
Java 函式式介面在 C# 中等效於委託。
下面讓我們瞭解 Java 中函式式介面的實現 −
示例
@FunctionalInterface public interface MyInterface { void invoke(); } public class Demo { void method(){ MyInterface x = () -> MyFunc (); x.invoke(); } void MyFunc() { } }
C# 委託中同樣的實現 −
示例
public delegate void MyInterface (); public class Demo { internal virtual void method() { MyInterface x = () => MyFunc (); x(); } internal virtual void MyFunc() { } }
廣告