做仿函数都在C#中的等价? [英] Do functors have an equivalent in C#?

查看:351
本文介绍了做仿函数都在C#中的等价?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个相当于函子在C#



C#有Func键<,>,代表和匿名方法,但并非所有这些指针的方法?



C ++的仿函数是一个类,而不是一个指针的方法。


解决方案

C#有Func键<,>,代表和匿名方法的但不所有这些指针的方法?


$乙
$ b

没有。即使是C#委托是类,编译器为你实现。这些生成的类(代表)从 MulticastDelegate 反过来从 代表



总之,委托是由编译器生成的类的语法糖。


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 from Delegate.

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

这篇关于做仿函数都在C#中的等价?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆