C # 2.0 Learning - Agent 2

xiaoxiao2021-04-08  422

// Copyright (c) Microsoft Corporation. All Rights Reserved.

// compose.csusing system;

Delegate void mydelegate (string s);

Class myclass {public static void hello (string s) {console.writeline ("Hello, {0}!", s);

Public static void goodbye (string s) {console.writeline ("Goodbye, {0}!", s);

Public static void main () {MyDelegate A, B, C, D;

// Create the delegate object a that references // the method Hello: a = new MyDelegate (Hello); // Create the delegate object b that references // the method Goodbye: b = new MyDelegate (Goodbye); // The two Delegates, A and B, Are Composed to form c, // Which calls Both methods in order: c = a b; // remove a from the composed delegate, Leaving D, // Which calls only the method goodbye: d = C - a;

Console.writeline ("Invoking Delegate A:"); A ("a"); "INVOKING DELEGATE B:"); B ("B"); console.writeline ("Invoking Delegate C:"); C ("c"); console.writeline ("Invoking Delegate D:"); D ("D");}}

CSC compose.cs

Compose

转载请注明原文地址:https://www.9cbs.com/read-132889.html

New Post(0)