当你使用C#的代表? [英] When would you use delegates in C#?

查看:150
本文介绍了当你使用C#的代表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是你代表的使用在C#?

What are your usage of delegates in C#?

推荐答案

现在,我们有拉姆达EX pressions和C#匿名方法,我使用委托得多。在C#1,在那里你总是必须有实现逻辑独立的方法,使用委托常常没有任何意义。这些天我使用委托的:

Now that we have lambda expressions and anonymous methods in C#, I use delegates much more. In C# 1, where you always had to have a separate method to implement the logic, using a delegate often didn't make sense. These days I use delegates for:

  • 在事件处理程序(GUI等)
  • 启动线程
  • 在回调(例如,用于异步API的)
  • LINQ和类似(List.Find等)
  • 在别的地方,我要有效地运用模板code有一些专门的逻辑中(其中委托提供专业化)

这篇关于当你使用C#的代表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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