Can someone distill into proper English what a delegate is?(有人可以提炼出适当的英语代表是什么吗?)
问题描述
有人可以将代表的含义分解为一个简单、简短、简洁的解释,同时包含目的和一般利益吗?我试着把我的头绕在这个问题上,但它并没有陷入困境.
Can someone please break down what a delegate is into a simple, short and terse explanation that encompasses both the purpose and general benefits? I've tried to wrap my head around this and it's just not sinking in.
推荐答案
用最简单的术语来说,它本质上是一个指向方法的指针.
In the simplest possible terms, it's essentially a pointer to a method.
您可以拥有一个保存委托类型的变量(就像您拥有一个可以保存 int 类型的 int 变量一样).您可以通过像函数一样调用变量来执行委托所指向的方法.
You can have a variable that holds a delegate type (just like you would have an int variable that can hold an int type). You can execute the method that the delegate points to by simply calling your variable like a function.
这允许您拥有可变函数,就像您可能拥有可变数据一样.您的对象可以接受来自其他对象的委托并调用它们,而无需自己定义所有可能的函数.
This allows you to have variable functions just like you might have variable data. Your object can accept delegates from other objects and call them, without having to define all the possible functions itself.
当您希望对象根据用户指定的条件执行操作时,这非常方便.例如,根据用户定义的真/假表达式过滤列表.您可以让用户指定委托函数以用作过滤器来评估每个列表项.
This comes in very handy when you want an object to do things based on user specified criteria. For example, filtering a list based on a user-defined true/false expression. You can let the user specify the delegate function to use as a filter to evaluate each list item against.
这篇关于有人可以提炼出适当的英语代表是什么吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:有人可以提炼出适当的英语代表是什么吗?


- C#MongoDB使用Builders查找派生对象 2022-09-04
- 输入按键事件处理程序 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01