Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

what are delegates? How you used then in your project?

Answer Posted / parmjit

/*

we can think deligate as a hook for a specific type of
function interfaces, to which we can hang functions whose
interfaces match with delegates interface. On a single call
to delegate, all the functions which are hooked to it, will
be called with the same parameters for which delegate was
called.


let's say we have two fuctions, both receive a string value
and prints it back on screen as follows. */

void print_lower(string s)
{
Console.writeline(s.ToLower());
}

void print_upper(string s)
{
Console.writeline(s.ToUpper());
}

//e.g. we can declare a delegate type as

delegate void ToPrint(string s);

//We can create it's instance as :

ToPrint tp;

tp = print_lower; // add a function to delegate
tp += print_upper; // add another function to delegate
tp += print_upper; // add one more function to delegate
tp += print_lower; // add one more function to delegate


//Now when we call

tp("Abcd");

/*it will print the following text on console screen


abcd
ABCD
ABCD
abcd

against a single call to delegate instance, all the
functions which were assined or added to it are called.

*/

Is This Answer Correct ?    10 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is data dictionary in c#?

860


How do you use nullable?

878


What are methods in C#?

898


What is the difference between int and int in c#?

934


Who benefits from ajax?

935


How is a strongly-named assembly different from one that isn’t strongly-named?

990


What is the signature of a method?

870


Explain hash table in c# ?

1020


Which is better interface or abstract class in c#?

762


Why are strings in c# immutable?

875


Can you inherit multiple abstract classes in c#?

877


What is the difference between list and dictionary in c#?

819


Which constructor is called first in c#?

880


What is the meaning of MSIL?

1159


Explain constructor in c#?

1245