PDA

View Full Version : what is delegate



/asra/
دوشنبه 29 بهمن 1386, 17:41 عصر
دوستان من جست و جو کردم ولی چیزی پیدا نکردم!
لینک what is delegate هم در قسمت مسائل و تاپیک های مهم درست کار نمی کنه!

می خوام بدونم delegate چیه؟ کسی می تونه من رو راهنمایی کنه؟

Mahdi.Kiani
دوشنبه 29 بهمن 1386, 22:23 عصر
به فرض هم که چنین چیزی را در این سایت پیدا نکردی
قرار نیست خودتو وابسته فقط همین سایت بکنی




A delegate is a type that references a method. Once a delegate is assigned a method, it behaves exactly like that method. The delegate method can be invoked like any other method, with parameters and a return value, as in this example:
public delegate int PerformCalculation(int x, int y);




منبع
http://msdn2.microsoft.com/en-us/library/ms173171.aspx





The delegate keyword is used to declare a reference type that can be used to encapsulate a named or an anonymous method. Delegates are similar to function pointers in C++; however, delegates are type-safe and secure. For applications of delegates, see Delegates and Generic Delegates.



منبع
http://msdn2.microsoft.com/en-us/library/900fyy8e.aspx






Delegate OverView

Delegates have the following properties:

Delegates are like C++ function pointers but are type safe.

Delegates allow methods to be passed as parameters.

Delegates can be used to define callback methods.

Delegates can be chained together; for example, multiple methods can be called on a single event.

Methods do not have to match the delegate signature exactly. For more information, see Covariance and ContravarianceCovariance and Contravariance in Delegates (C# Programming Guide).

C# version 2.0 introduced the concept of Anonymous Methods, which allow code blocks to be passed as parameters in place of a separately defined method. C# 3.0 introduced lambda expressions as a more concise way of writing inline code blocks. Both anonymous methods and lambda expressions (in certain contexts) are compiled to delegate types. Together, these features are now known as anonymous functions. For more information about lambda expressions, see Anonymous Functions (C# Programming Guide).

اَرژنگ
سه شنبه 30 بهمن 1386, 02:17 صبح
دوستان من جست و جو کردم ولی چیزی پیدا نکردم!
لینک what is delegate هم در قسمت مسائل و تاپیک های مهم درست کار نمی کنه!

می خوام بدونم delegate چیه؟ کسی می تونه من رو راهنمایی کنه؟

به شکل خلاصه برایه این استفاده میشه که شما بتوانید بگید که من قراره از یک متد که آرگومنهاش شکل بخصوصی هستند و تایپ بخصوصی که میتوانند برگردانند استفاده خواهم کرد، الان نمیدونم این متد چی هست ولی هر متدی که از این الگو پیروی کند را میشد به جاش استفاده کرد. یعنی یک چیزی مانند استفاده از متغییر برایه متد، منتها به جایه اینکه متغییر مقدار بخصوصی بگیرد ، متد بخصوصی را میگریه