使用代表有什么缺点吗? [英] Are there any disadvantages of using delegates ?
问题描述
你好,
我是C#编程的新手,我正在使用代表参加活动 -
驱动的应用程序,发现它们非常有用。 />
是否有代理可能没用的应用程序?可以
任何人请告诉我使用
代表的不利之处。
谢谢,
James。
Hello,
I am new to C# programming and I am using delegates for the event-
driven application and found them very useful.
Are there any applications where delegates may not be useful ? Can
anyone please let me know what are the disadvantages of using
delegates.
Thanks,
James.
推荐答案
委托只是一个匿名函数指针。它允许你更多
自由配置对任何带有
代表签名的方法的调用。
我不知道任何代表没有用的应用程序,除了
或许试图通过Web服务委派。 :-)
但是,有些情况下,您不应该使用委托。例如,
在同一个类中调用私有方法。这只是一种方法
来电。
-
Gregory A. Beamer
MVP,MCP:+ I,SE,SD,DBA
订阅我的博客
http://feeds.feedburner.com/GregoryBeamer#
或者只是阅读它:
http://feeds.feedburner.com/GregoryBeamer
******************************************** >
|创造性思考! |
***************************************** ***
" James" < bo ************* @ gmail.comwrote in message
news:3a ***************** ***************** @ m3g2000h sc.googlegroups.com ...
A delegate is simply an anonymous function pointer. It allows you to more
freely configure a call to any method that bears the same signature of the
delegate.
I don''t know of any application where a delegate is not useful, except
perhaps trying to delegate across a web service. :-)
There are situations, however, you should not use a delegate. For exmample,
calling a private method in the same class. That would simply be a method
call.
--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA
Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#
or just read it:
http://feeds.feedburner.com/GregoryBeamer
********************************************
| Think outside the box! |
********************************************
"James" <bo*************@gmail.comwrote in message
news:3a**********************************@m3g2000h sc.googlegroups.com...
您好,
我是C#编程的新手,我正在使用代表参加活动 -
驱动的应用程序并发现它们非常有用。
是否有任何应用程序代表可能没有用?可以
任何人请告诉我使用
代表的不利之处。
谢谢,
詹姆斯。
Hello,
I am new to C# programming and I am using delegates for the event-
driven application and found them very useful.
Are there any applications where delegates may not be useful ? Can
anyone please let me know what are the disadvantages of using
delegates.
Thanks,
James.
2008年10月3日星期五09:14:07 -0700,牛仔(Gregory A. Beamer)
< No************@comcast.netnospammwrote:
On Fri, 03 Oct 2008 09:14:07 -0700, Cowboy (Gregory A. Beamer)
<No************@comcast.netnospammwrote:
委托只是一个匿名函数指针。它允许你更自由地配置对具有相同签名的任何方法的调用
代表。
我不知道任何代表没有用的应用程序,除了
或许试图通过Web服务委派。 :-)
但是,有些情况下,您不应该使用委托。对于
exmample,在同一个类中调用私有方法。这只是一个方法调用。
是一个方法调用。
A delegate is simply an anonymous function pointer. It allows you to
more freely configure a call to any method that bears the same signature
of the delegate.
I don''t know of any application where a delegate is not useful, except
perhaps trying to delegate across a web service. :-)
There are situations, however, you should not use a delegate. For
exmample, calling a private method in the same class. That would simply
be a method call.
好吧,更一般地说:当方法名称为
时调用_any_方法
实际上在编译时总是已知且可访问,即使方法
受保护,公共或内部。在这种情况下使用
委托是没有意义的。
但是,对于实际委托代理的情况,开销
很小,设计效益显着。所以,就这一点而言,我认为没有具体理由拒绝使用代表。
Pete >
10月3日,11:53 * am,Peter Duniho < NpOeStPe ... @nnowslpianmk.com>
写道:
On Oct 3, 11:53*am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
周五,2008年10月3日09:14:07 -0700 ,牛仔(Gregory A. Beamer)*
< NoSpamMgbwo ... @ comcast.netnospammwrote:
On Fri, 03 Oct 2008 09:14:07 -0700, Cowboy (Gregory A. Beamer) *
<NoSpamMgbwo...@comcast.netnospammwrote:
代表只是一个匿名函数指针。它允许你*
更自由地配置对任何具有相同签名*
代表的方法的调用。
A delegate is simply an anonymous function pointer. It allows you to *
more freely configure a call to any method that bears the same signature *
of the delegate.
我不知道任何代表没有用的应用程序,除了*
或许试图委派跨Web服务。 :-)
I don''t know of any application where a delegate is not useful, except *
perhaps trying to delegate across a web service. :-)
但是,有些情况下,您不应该使用委托。对于*
exmample,在同一个类中调用私有方法。这只是一个方法调用*
。
There are situations, however, you should not use a delegate. For *
exmample, calling a private method in the same class. That would simply*
be a method call.
嗯,更一般地说:当方法名称为*
时调用_any_方法
实际上总是在编译时已知且可访问,即使方法*
受保护,公共或内部。 *在这种情况下使用*
委托是没有意义的。
但是,对于实际委托代理的情况,开销*
很小,设计效益显着。 *所以,就此而言,我* b $ b同意没有具体理由拒绝使用代表。
Pete
Well, more generally: when calling _any_ method when the method name is *
actually always known and accessible at compile time, even if the method *
is protected, public, or internal. *It would be pretty pointless to usea *
delegate in that situation.
But, for situations where a delegate is actually called for, the overhead*
is minimal and the design benefit significant. *So, as far as that goes, I *
agree that there''s no specific reason to shun the use of a delegate.
Pete
非常感谢
James
Thanks a lot
James
这篇关于使用代表有什么缺点吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!