Back to Basics:
Delegates
Rob Hale
April 21, 2014
Goals
● Delegation pattern review
● Delegates in C#
Delegation
Design Pattern
Delegation design pattern - simple
Delegator Delegatee
Delegation design pattern
- slightly more complicated
Delegator IDelegatee
Concrete
Delegatee1
Concrete
Delegatee2
Coding time...
Delegates in C#
What are Delegates?
● Delegates are a reference type that defines
a method signature
○ Like C++ function pointers but are type safe
○ Unlike method overloading, the return type is part of
the signature
● They allow methods to be passed as
parameters
● They can be used to define callback
methods
● They can be chained together
○ For example, multiple methods can be called on a
Coding Time...
Resources
Code from this presentation
● https://github.
com/robhalevt/20140421_VTdotNET_DelegationAndDelegates
Other reading
● http://msdn.microsoft.com/en-us/library/vstudio/ms173171(v=vs.100).aspx
● http://msdn.microsoft.com/en-us/library/orm-9780596516109-03-09.aspx
● http://en.wikipedia.org/wiki/Delegation_pattern
● http://stackoverflow.com/questions/2044301/what-is-delegate

VT.NET user group 2014-04-21: Delegation and C# delegates

  • 1.
    Back to Basics: Delegates RobHale April 21, 2014
  • 2.
    Goals ● Delegation patternreview ● Delegates in C#
  • 3.
  • 4.
    Delegation design pattern- simple Delegator Delegatee
  • 5.
    Delegation design pattern -slightly more complicated Delegator IDelegatee Concrete Delegatee1 Concrete Delegatee2
  • 6.
  • 7.
  • 8.
    What are Delegates? ●Delegates are a reference type that defines a method signature ○ Like C++ function pointers but are type safe ○ Unlike method overloading, the return type is part of the signature ● They allow methods to be passed as parameters ● They can be used to define callback methods ● They can be chained together ○ For example, multiple methods can be called on a
  • 9.
  • 10.
    Resources Code from thispresentation ● https://github. com/robhalevt/20140421_VTdotNET_DelegationAndDelegates Other reading ● http://msdn.microsoft.com/en-us/library/vstudio/ms173171(v=vs.100).aspx ● http://msdn.microsoft.com/en-us/library/orm-9780596516109-03-09.aspx ● http://en.wikipedia.org/wiki/Delegation_pattern ● http://stackoverflow.com/questions/2044301/what-is-delegate