Why does trying to understand delegates feel like trying to understand the nature of the universe?(为什么试图理解代表感觉就像试图理解宇宙的本质?)
问题描述
我读过两本书,有很多例子.他们对我来说仍然几乎没有意义.我可能会编写一些使用委托的代码,但我不知道为什么.我是唯一有这个问题的人,还是我只是个白痴?如果有人能真正向我解释我何时、何地以及为什么我会实际使用代理,我会永远爱你.
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.
这篇关于为什么试图理解代表感觉就像试图理解宇宙的本质?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么试图理解代表感觉就像试图理解宇宙的本质?


基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01