Lecture overview -- Keyboard shortcut: 'u'  Previous page: Delegates [Section] -- Keyboard shortcut: 'p'  Next page: Delegates that contain instance methods -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 33 : 45
Object-oriented Programming in C#
Data Access and Operations
Delegates in C#

Delegates are types. The objects in such types are methods. With the introduction of delegates, methods become data.

A delegate is a type the values of which consist of methods

Delegates allow us to work with variables and parameters that contain methods

/user/normark/oop-csharp-1/sources/c-sharp/delegates/1/Application.csA Delegate of simple numeric functions. This program is explained

An example which defines a simple delegate (a type of methods) called NumericFunction. The example illustrates both existing, named methods in NumericFunction and a new, anonymous method in in the type.

/user/normark/oop-csharp-1/sources/c-sharp/delegates/1/outputOutput from the NumericFunction delegate program.


/user/normark/oop-csharp-1/sources/c-sharp/delegates/2/Application.csThe static method Compose in class Application. This program is explained

Illustrates a method that takes two NumericFunction objects as input, and which returns a NumericFunction.

/user/normark/oop-csharp-1/sources/c-sharp/delegates/2/outputOutput from the Compose delegate program.


Delegates make it possible to approach the functional programming style

Methods can be passed as parameters and returned as results to and from other methods

Go to exerciseFinding and sorting elements in an array
Read more about delegates in the text book version of this material.