Click here to Skip to main content
13,589,767 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 11 Feb 2010
Licenced CPOL

Basic Understanding for Delegate Code

, 11 Feb 2010
Rate this:
Please Sign up or sign in to vote.
How to code for Delegate In this artical explains basic understanding for delegate and how to create nad use delegate. This code for .net framework for C# This artical is usefull...

How to code for Delegate

In this artical explains basic understanding for delegate and how to create nad
use delegate.

This code for .net framework for C#

This artical is usefull for .net(C#) developers who requires basic understanding
for delegate concept

Using the code

Delegate is a class that can hold a reference to a method or a function. Delegate
class has a signature and it can only reference those methods whose signature is
compliant with the class. Delegates are type-safe functions pointers or callbacks

Below is the code for delegates

delegate int CalculateArea();
delegate int CalculateAreaParam(<span
    class="code-keyword">int</span> i, int j);
public void CallDelegate()
    CalculateArea CallMethod = new CalculateArea(Calculate);
public int Calculate()
    return 5 * <span
public void CallDelegateParam(<span
    class="code-keyword">int</span> i, int j)
    CalculateAreaParam CallMethod = new CalculateAreaParam(CalculateParam);
    Response.Write(CallMethod.Invoke(i, j));
public int CalculateParam(<span
    class="code-keyword">int</span> i, int j)
    return i * j;

As above code we have created two delegate CalculateArea and CalculateAreaParam.One
is without any parameter and other one is with paramter.

In this code In this method CallDelegate, we have created object for CalculateArea.
This object is initated by Calculate . Once we invoke this object it will calculate
method. Here we have created anther delegate CalculateAreaParam which is with parameter
so while invoking this method we need to pass relavant parameter so it will call
appropriate iniated methods.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Amit M patel
Technical Lead Accenture Services
India India
I have total more then 6.6 years of IT Industry experience....

I have comlated my Diploma in Computern Engineering in 2003...

I have also cleared Microsoft Certified Professional Developer Specailist Exams for enterprise edition.

I have also cleared Microsoft Certified Technologies Specailist Exams for web,window and distribute application

I have write couple of article regarding .net,,SSRS, Documentum, COM,DCOM,web services,Indesign Server SDK which is published in many web sites.....

I have worked on differnet patterns like Factory, Decorative, facade, MVP.

You may also be interested in...


Comments and Discussions

Generalpurpose... Pin
Diamonddrake12-Feb-10 17:06
memberDiamonddrake12-Feb-10 17:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.180615.1 | Last Updated 12 Feb 2010
Article Copyright 2010 by Amit M patel
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid