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() {
}
}
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP