Programming Training | New Way New Style
A Step-by-Step ASP.NET Tutorial for Beginners - blog.udemy.com
MAHAK: Society to Support Children, Suffering from Cancer
Read Valuable Verse From Cosmic References Quran & Bible

Delegate

Mahsa Hassankashi | Sunday 1 2016 0:14


Delegate from basic



What is Delegate

Remember primary time when you (was newer in .net) definedyour first variable:


Delegate

Delegate is like that but in the most time we assign methodinstead of variable to that.

In general declaration area write:


Delegate


And inside your event assign your method to delegate:

Delegate

In another words delegate is a pointer to method like C++,but with this difference that delegate is type safe due to it must be the samein number and data type for inputs and outputs: Be the same in inputs andoutputs reminds us Interface concept, so if we have interface why we needdelegate?

Delegate

In fact delegate creates and raises our requirement functionin run time mode and it can be confidence representative even for more than onemethod.

Assume you want to write application which is a calculator:


Delegate

Delegate

Delegate

In the above example if you want to invoke delegate you passan integer number to getdel method which point to the “Add”, but you can invokeall of your method sequentially (one after another one)

Delegate

When you invoke delegate pointer it call all of those methodsequentially:

Delegate

Actually multicast delegate is used whenever we want tobroadcast simultaneously tasks such as whenever an event is raised some relatedactions occur after that. Assume you have account in the bank and before youtold your bank to activate your notification to your “email”, “send sms to yourmobile” or “deliver print from ATM”, so after you do ATM or any transaction youwill receive all of your notification simultaneously.

Those events that determine when an event is raised arepublishers and those ones that determine what actions should be taken in theresponse of publisher event are subscriber.


Delegate

Delegate


Delegate


And the file has been created in specific root:


Delegate






Delegate









Delegate










Above picture shows that delegate is open in front designand if you want to block it and when write mdel (“Delegate”) and hit dot (“.”)you do not want to appear all of method such as “BeginInvoke” , “Clone” and etcso you should use eventhandler to encapsulate your delegate.

Project Name (RC) àAdd New Item àWeb User Control àName it : WebUserControl.ascx

Drag and drop one button on that




Create web form and in solution explorer click on your webuser control and drag it to your design web form such as:








Then event has upper hand to manage delegate and it is nowmore encapsulated:




Download Delegate File From Here






Tag: ,, , , , , ,

Rss Feed

Feedback: Feel free to leave any feedback on this article; it is a pleasure to see your comments about this code. If you have any questions, please do not hesitate to ask me here.
Your email address will not be published. All fields are Required





Aahna Lourn | Friday 9 2014 18:48
Great Article , So useful
Kenneth | Friday 9 2014 22:11
Nice !
Renju | Saturday 9 2014 2:4
helpful
Solomon | Friday 9 2014 14:27
Good one
Mayur Nimbalkar | Monday 9 2014 8:26
Really Useful. Thank you for sharing this.
Sadegh | Saturday 12 2014 5:39
Nice ! Very Good
Rizwan | Wednesday 1 2015 0:54
very useful :)
Ahmed | Wednesday 1 2015 23:53
Very clear... Keep up the good work and good luck..
MAhdi | Friday 8 2015 11:53
great article thanks
Dev Sharma | Tuesday 9 2015 11:5
Dear Mahsa Madam, Your blog is very informative. It help me to understand topic clearly. But finding difficult to understand Delegate due to broken images. Please check this link : http://technical.cosmicverse.info/Article/Index/1
Mahsa Hassankashi | Sunday 1 2016 0:56
Dear @Dev Sharma, thank you for your accurate consideration. I have corrected images and so sorry for delay in response.