Search code examples
c#c++functor

Do functors have an equivalent in C#?


Is there an equivalent to Functors in C#?

C# has Func<,>, delegates and anonymous methods but aren't all of these pointers to a method?

The C++ Functor is a class and not a pointer to a method.


Solution

  • C# has Func<,>, delegates and anonymous methods but aren't all of these pointers to a method?

    No. Even C# delegates are classes, implemented by the compiler for you. These generated classes (for delegates) are derived from MulticastDelegate which in turn derives from Delegate.

    In short, a delegate is a syntactic sugar for a class generated by compiler.