C # Delegate

Source: Internet
Author: User

About entrust oneself in the work seldom encounter, gradually feel is not very important, but in the written test is often tested, so turned to write the data to see a bit, the delegate name is called to give things to others to do, I will be a story of the way to explain what the delegation is.

I've got two people in here.

Pmwang
//1.0 Lao Wang intends to add a computer        Private int_num =1;  Public voidBuycomputer () {//2.0 but no time! Tell Xiao Li to buy it? Console.WriteLine ("Xiao Li goes to buy a computer"); //5.0 Ask Xiao Li to buybuydelegate (_num); }        //3.0 Lao Wang is going to ask Xiao Li to buy this place and define a delegate.         Public Delegate voidLetlibuycomputer (intnum); //4.0 declaring this delegate         PublicLetlibuycomputer buydelegate;

SELi

        //Xiao Li has a way to buy a computer.         Public voidBuycomputer (intnum) {Console.WriteLine ("Okay, good! "); Console.WriteLine ("out"); Console.WriteLine ("by car"); Console.WriteLine ("Buy to a computer"); Console.WriteLine ("Back to company"); Console.WriteLine ("Li: Manager Wang I bought a computer for one day"); }

Main ()

Static voidMain (string[] args) {            //1.0 Old King's here.Pmwang Wang =NewPmwang (); //2.0 Xiao Li is here.SELi Li =NewSELi (); //4.0 The old King's commission first look at 3.0 good understanding of this delegation process note: cannot be changed in programmingWang.buydelegate =NewPmwang.letlibuycomputer (li.            Buycomputer); //3.0 Lao Wang buys a computerWang.            Buycomputer ();        Console.read (); }

When performing Wang. Buycomputer () Call old Wang buy computer, Lao Wang do not want to go to buy a computer a series of procedures entrusted to Xiao Li, small Lee Buycomputer () is to perform the action of buying a computer. This is the commissioning of the purchase of computer methods, the action of the performer is Xiao Li's buycomputer ().

C # Delegate

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.