Simple Example 1

Source: Internet
Author: User

 

1 using System;
2 using System. Collections. Generic;
3 using System. Linq;
4 using System. Text;
5
6 namespace @ delegate
7 {
8 class MultiDelegateExam
9 {
10 delegate void Dialoging ();
11 public static void Greeting ()
12 {
13 Console. WriteLine ("How are you! ");
14}
15 public static void Introduce ()
16 {
17 Console. WriteLine ("I am Norosin .");
18}
19 public static void Main (string [] args)
20 {
21 Dialoging oneDialoging = new Dialoging (Greeting );
22 Console. WriteLine ("single delegate: one ");
23 oneDialoging ();
24 Console. WriteLine ();
25
26 Dialoging twoDialoging = new Dialoging (Introduce );
27 Console. WriteLine ("single delegate: two ");
28 twoDialoging ();
29 Console. WriteLine ();
30
31 Dialoging threeDialoging = oneDialoging + twoDialoging;
32 Console. WriteLine ("multicast delegate: one + two ");
33 threeDialoging ();
34 Console. WriteLine ();
35
36 Dialoging fourDialoging = threeDialoging-twoDialoging;
37 Console. WriteLine ("single delegate: three-two ");
38 fourDialoging ();
39 Console. WriteLine ();
40
41 Console. WriteLine ("press Enter to exit ");
42 Console. Read ();
43}
44}
45}
46
47 running results:

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.