为什么试图理解代表感觉就像试图理解宇宙的本质?

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.

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)