1. Entrusted delegate
The delegate delegate is also a type that can declare a delegate where any class can be declared, and it passes the method as a parameter of another method, so that different methods can be passed to accomplish different functions to make the program very extensible.
Example:
Suppose there is a computer, someone will use it to write programs, some people will use it to play games, some people will use it to watch movies, some people will use it to listen to music while playing games, some people will use it while listening to music while reading documents, the edge of QQ.
This computer can be abstracted into a class computer, there is a method dowork, all people have to do their own things through this method.
We can implement some fixed things without a delegate, not flexible enough:
For example:
The code is as follows:
Class Program {
static void Main (string[] args) {
Computer computer = new computer ();
Computer. DoWork ("Pig", "watching a movie!" ”);
Computer. DoWork ("The Sand Monk", "in writing the program!") ”);
Computer. DoWork ("Monkey King", "playing the game!") ”);
}
}
public class Computer {
public void DoWork (string name, string work) {
Console.WriteLine ("{0}{1}", name, work);
}
}
In addition to the Declaration,
Running GuestArticles are original, reproduced please link to the form of the address of this article
Delegate, event Learning notes in C #
This address: http://www.paobuke.com/develop/c-develop/pbk23183.html
Related content examples of pirate split-gold algorithm implemented by C # use WebClient to log in to the Web site and crawl the login Web page information implementation Method C # in the use of string StringBuilder StringBuffer Class C # webclient implement file download
Example of a queue (Quene) for C # Data structures Introduction to the beginning of self-study of C # Programming introduce partial methods and partial class analysis in C # WinForm implementing methods for capturing forms to minimize, maximize, and Close button events
Delegate, event Learning notes in C #