Sunday, 3 February 2013

Delegate


By on 04:38

Delegate is similar to interface,but the main difference between delegates and interface is delegate created at runtime whereas interface created at compile time.Delegate is also called as safe  function pointers.Or a simple definition of delegate is function which call another function.

Syntax includes:-

->Declaration
->Instantiation
->Method define
->Invocation

Now we take an example:-

Delegate in c #(c sharp),java calls more than one function.

namespace console application 23
{
delegate int multiply-divide(int x,int y)
class md
{
public static int multiply(int a,int b)
{
return(a*b);
}
public static int divide(int a,int b)
{
return(a-b);
}
}
class program
{
static void main(string[],agrs)
{
multiply-divide obj=new multiply-divide(md.multiply);
multiply-divide obj1=new multiply-divide(md.divide);
int ret1=obj(12,55);
int ret2=obj1(30,10);
Console.WriteLine(+ret1);
Console.WriteLine(+ret2);
Console.Read();
}
}
}

That's all about Delegate and its definition(meaning,means).If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.


0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...