Home > Backend Development > C#.Net Tutorial > C# equivalent of Java functional interfaces

C# equivalent of Java functional interfaces

PHPz
Release: 2023-08-26 12:09:11
forward
1294 people have browsed it

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() {
   }
}
Copy after login

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() {
   }
}
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template