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.
这篇关于为什么试图理解代表感觉就像试图理解宇宙的本质?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么试图理解代表感觉就像试图理解宇宙的本质?
基础教程推荐
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 如果条件可以为空 2022-01-01
- 将数据集转换为列表 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
