为什么试图了解代表们感觉就像试图了解宇宙的本质? [英] Why does trying to understand delegates feel like trying to understand the nature of the universe?

查看:114
本文介绍了为什么试图了解代表们感觉就像试图了解宇宙的本质?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过两本书,吨的例子。他们还让旁边没有了意义。我大概可以编写使用一些代表代码,但我不知道为什么。我是唯一一个有这个问题,还是我只是一个白痴?如果任何人都可以真正给我解释一下何时,何地,为什么我会实际使用委托,我将永远爱你。

I've read two books, tons of examples. They still make next to no sense to me. I could probably write some code that uses delegates, but I have no idea why. Am I the only one with this problem, or am I just an idiot? If anyone can actually explain to me when, where, and why I would actually use a delegate, I'll love you forever.

推荐答案

代表仅仅是通过周围的函数在一个变量的方式。

Delegates are just a way to pass around a function in a variable.

您传递一个委托函数做一个回调。这样做异步IO时一样,您通过委派功能,当数据被读出硬盘将被调用(你曾与委托参数写的函数)。

You pass a delegated function to do a callback. Such as when doing asynchronous IO, you pass a delegated function (a function you have written with the delegate parameter) that will be called when the data has been read off the disk.

这篇关于为什么试图了解代表们感觉就像试图了解宇宙的本质?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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