Home  >  Article  >  Backend Development  >  C# equivalent of Java functional interfaces

C# equivalent of Java functional interfaces

PHPz
PHPzforward
2023-08-26 12:09:111239browse

C# 相当于 Java 函数式接口

#Java’s functional interface is equivalent to Delegate in C#.

Let us see the implementation of functional interface in Java -

Example

@FunctionalInterface
public interface MyInterface {
   void invoke();
}
public class Demo {
   void method(){
      MyInterface x = () -> MyFunc ();
      x.invoke();
   }
   void MyFunc() {
   }
}

C# The same implementation in Delay -

Example

public delegate void MyInterface ();
public class Demo {
   internal virtual void method() {
      MyInterface x = () => MyFunc ();
      x();
   }
   internal virtual void MyFunc() {
   }
}

The above is the detailed content of C# equivalent of Java functional interfaces. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete