CSE459_CSharp_04_Delegates

CSE459_CSharp_04_Del - Programming in C Delegates Delegates CSE 494R(proposed course for 459 Programming in C Prof Roger Crawfis Delegates

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Programming in C# Delegates Delegates CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis Delegates Delegates are type definitions for function pointers . Once defined, they allow for type-safe (static) variables (instances) which point to functions (methods). They specify the signature of an individual method. public delegate Complex Func1D(Complex x); Return Type Parameters: order and type Type Definition Name This name does not matter. Delegates vs. Interfaces Delegates are similar to interfaces: they specify a contract between a caller and an implementer. Interface: specifying an entire interface Delegate: specifying a single function Interface: created at compile-time Delegate: created at run-time. Can be used to dynamically hook up callbacks between objects that weren’t originally designed to work Examples The following are type definitions: public delegate double Function( double x ); public delegate bool Predicate( double x ); public delegate void Action( double x ); We can now assign variables these types: private Function log10 = System.Math.Log10; private Predicate isNegative = null ; private Function operation = null ; private...
View Full Document

This note was uploaded on 02/27/2012 for the course CSE 459.24 taught by Professor Crawfis during the Winter '11 term at Ohio State.

Page1 / 12

CSE459_CSharp_04_Del - Programming in C Delegates Delegates CSE 494R(proposed course for 459 Programming in C Prof Roger Crawfis Delegates

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online