.NET Delegates are objects which can refer to static and instance methods in memory at runtime and can call those methods in your program. In this tutorial I will show you how you can create and use delegates in C#.
To explain delegates and their use in real world programs I am creating a BankAccount class in which I will declare one delegate using C# delegate keywork.
To test BankAccount class create one Windows Form Application using C# and in the Form Load event create object of BankAccount class as shown below

Following code is calling BankAccount class methods on Deposit and Withdraw button click events.
Following methods are event handlers methods attached with delegate type events OnDeposit and OnWithdraw
Nice tutorial. but i feel difficulty in following code:
account.OnDeposit += new BankAccount.BankDelegate(account_OnDeposit);
Please kindly explain it for me.
Waqas,
This is the first piece of Visual C# code I’ve seen dealing with delegates that actually makes sense. Much, much thanks.
My experience with reference manuals is that they are totally divorced from real life programming. So again, much, much thanks.
Still, I don’t have a clear picture of the advantages and disadvantages of using delgates, so any additional information or code on delegates would be helpful.
Ted
.
Sir thank you very much for you post… Its really helpful…
Best delegate tutorial yet…well done
nice tut
very nice
Thanks for give Delegates with Events tutorial,it is helpful for learning dotnet 2.0.
Thanks
Santosh Kumar
http://www.operativesystems…