Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do functors have an equivalent in C#? [duplicate]

Tags:

c++

c#

functor

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.

like image 546
4thSpace Avatar asked Dec 16 '22 09:12

4thSpace


1 Answers

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.

like image 195
Nawaz Avatar answered Dec 29 '22 06:12

Nawaz