Click here to load reader
Upload
rob-hale
View
253
Download
0
Embed Size (px)
DESCRIPTION
Slides from my April 2014 presentation to the Vermont .NET user group.
Citation preview
Back to Basics: DelegatesRob HaleApril 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 single event
Coding Time...
ResourcesCode 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