C# Equivalent to Java Functional Interfaces

CsharpProgrammingServer Side Programming

Equivalent of Java’s Functional Interfaces in C# is Delegates.

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

The same implementation in C# delagates −

Example

public delegate void MyInterface ();
public class Demo {
   internal virtual void method() {
      MyInterface x = () => MyFunc ();
      x();
   }
   internal virtual void MyFunc() {
   }
}
raja
Published on 31-Aug-2018 15:22:19
Advertisements