C# Equivalent to Java Functional Interfaces


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

mkotla
mkotla

e

Updated on: 22-Jun-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements