Interviews3 answers
3 Answers
Delegate is a function pointer. We can pass method as a parameter.
Public Delegate bool DelActive();
Static voind main()
{
DelActive a= new DelActive(IsDone);
IsUser(a);
bool IsDone()
{
int x=10;
if(x==10)
{
return true;
}
else
{
return false;
}
}
}
Class sample
{
Public bool IsUser(DelActive active)
{
if(active) { return true; }
else
{
return false;
}
}
}
Pramod VermaPosted Jan 24, 2015, 9:05 AM EST
Delegate is a function pointer. We can pass method as a parameter.
Public Delegate bool DelActive();
Static voind main()
{
DelActive a= new DelActive(IsDone);
IsUser(a);
bool IsDone()
{
int x=10;
if(x==10)
{
return true;
}
else
{
return false;
}
}
}
Class sample
{
Public bool IsUser(DelActive active)
{
if(active) { return true; }
else
{
return false;
}
}
}
Pramod VermaPosted Jan 24, 2015, 9:04 AM EST
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, as in this example:
public delegate int PerformCalculation(int x, int y);
Amit PatelPosted Jun 26, 2012, 12:11 AM EDT

