Wrox Programmer Forums
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 3rd, 2004, 05:55 AM
Authorized User
 
Join Date: Sep 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default Delegates

Delegates
---------------
- a type that enables the storage of references to functions.


Declaration
----------------
- like functions, but without a body, using the 'delegate' keyword.

    i.e. public delegate double processDelegate( double a, double b );


- it specifies a function signature consisting of a return type & parameter list.


Usage
---------------
- after the delegation definition, it can be used as a type to declare a variable.

    i.e. processDelegate process;


- the delegate variable can then be a reference to any function that has the same signature, ( ie return type & parameters ).

    i.e.
        static double Multiply( double p1, double p2 )
        {
            ...
        }

        static double Divide( double p1, double p2 )
        {
            ...
        }

        process = new processDelegate( Multiply );
         // process = new processDelegate( Divide ); <-- alternative

- once this is completed, the assigned function can be called using the delegate variable.

    i.e. process( p1, p2 );


PLEASE NOTE
---------------
- different from polymorphism, since only concerened with methods in base & child with same name.
- whereas delegates are to do with any method as long as they have the same signature !!
- the real purpose of delegates is to do with events/event handling.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with delegates mike_remember ASP.NET 1.0 and 1.1 Professional 2 November 7th, 2006 12:33 AM
Delegates RalphJr C# 2005 1 April 29th, 2006 08:06 AM
Delegates pramos.21d C# 1 April 11th, 2006 03:43 AM
Help with Delegates mike_remember ASP.NET 1.0 and 1.1 Basics 4 October 4th, 2005 07:32 AM
I still Don't get Delegates p_nut33 Pro VB.NET 2002/2003 2 April 26th, 2004 01:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.