做仿函数都在C#中的等价? [英] Do functors have an equivalent in C#?
问题描述
有一个相当于函子在C#
C#有Func键<,>,代表和匿名方法,但并非所有这些指针的方法?
C ++的仿函数是一个类,而不是一个指针的方法。
C#有Func键<,>,代表和匿名方法的但不所有这些指针的方法?
块引用> $乙
$ b没有。即使是C#委托是类,编译器为你实现。这些生成的类(代表)从
MulticastDelegate $ C $派生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.
解决方案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 fromDelegate
.In short, a delegate is a syntactic sugar for a class generated by compiler.
这篇关于做仿函数都在C#中的等价?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!