Click Here for 3 Month Free of ASP.NET Hosting!
Home | Submit an interview question | Filter by category | Filter by job function | Filter by company
 
Member Information
User Id
Password
 
Forgot Password
Technology Category
.NET (1202)
Languages (103)
Database (146)
Operating System (48)
Reporting (5)
Third-Party Tools (2)
Testing (91)
OOP (75)
Web Development (40)
Design Patterns (89)
General (9)
Networking (88)
Hardware (63)
Brain Exercise (2)
Others (37)
 Our Network
.NET Heaven
C# Corner
Interview Corner
Longhorn Corner
Mindcracker
VB.NET Heaven
Home » .NET » .NET
what is delegate
Posted by reeta Jun 20, 2009
Viewed : 647 times
Major Category : .NET
Minor Category : ASP.NET
Total Replies : 6
Become a Sponsor
 EDITORIAL ANSWER  
No Reply Yet
 ANSWERS BY USERS  
PEEYUSH MISHRA
Jul 21, 2009

Delegate is a type safe Functional Pointer. it hold method or methods reference in an object.effective use of delegate to improve performance of application.

Declaration

public delegate type_of_delegate delegate_name(var_type var1,var_type var2)

Note :-

  1. you can use delegate with parameters or without parameters
  2. you should follow the same syntax as in the method

Sample program using Delegate

//delegate Declaration

public delegate double delegate_prod(int a,int b)

Class Class1

{

   //method with the same parameters and same signature

   static double fnprodvalue(int val1,int val2)

    {

        return var1*var2;

    }

   static void main(string[] args)

  {

      //creating delegate instance

      delegate_prod objDelegate =new delgate_prod(fnprodvalue);

     double res = objDelegate(5,4);

      console writeline("Result :",  + res);

      console.readline():

   }

}

Delegates are two types

single caste -single caste delegate refers only one function address after creating the instance variable

multi-caste delegate- multi-caste refers to multi-single caste delegate features

raghu pabba
Jun 29, 2009
Delegate is a Functional Pointer and it acts as a reference type too. Depending on function prototype we have to declare the delegates. It takes arguments as well as return types also. they are two types single caste and multi-caste delegate. single caste delegate refers only one function address after creating the instance variable.and it holds only one method address. were as multi-caste refers to multi-single caste delegate features. i.e we can access multiple features from the class.
pula narasima
Jun 26, 2009

A delegate in C# is similar to a function pointer in C or C++. Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object. The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked.

Examples:
using System;

namespace Akadia.BasicDelegate
{
    // Declaration
    public delegate void SimpleDelegate();

    class TestDelegate
    {
        public static void MyFunc()
        {
            Console.WriteLine("I was called by delegate ...");
        }

        public static void Main()
        {
            // Instantiation
            SimpleDelegate simpleDelegate = new SimpleDelegate(MyFunc);

            // Invocation
            simpleDelegate();
        }
    }
}

 

Bishwajit Saha
Jun 26, 2009
One important features of delegate is It can be invoked asynchronously. That method would be executed in different thread. Even you can receive return type.
naininaveen kumar
Jun 23, 2009

Delegates works as a functional pointers.Delegates are pure safe they hide the actual

information.Delegate may point aome function or more than one function.Delegates

may return a value.Delegates are declared class level,structurelevel,module level,

global level.

 

Nikhil Kumar
Jun 21, 2009

Delegate

A delegate is a type that references a method. Once a delegate is assigned a method, it behaves exactly like that method. The delegate method can be used like any other method, with parameters and a return value,

Visit

www.dotnetask.blog.co.in

  
1

 

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Advertise with us
Current Version: 2.2009.3.2
 © 1999 - 2009  Mindcracker LLC. All Rights Reserved