有人可以提炼出适当的英语代表是什么吗? [英] Can someone distill into proper English what a delegate is?

查看:8
本文介绍了有人可以提炼出适当的英语代表是什么吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以将代表的含义分解为一个简单、简短、简洁的解释,同时包含目的和一般利益吗?我试着把我的头绕在这个问题上,但它并没有陷入困境.

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.

这篇关于有人可以提炼出适当的英语代表是什么吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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