DELEGATE simple example

zhaozj2021-02-16  104

//

************************************************* /

/ ** /

/ * Delegate sample / * // *************************************************** *********************** /

Using

System;

Namespace

Eventtest

{// Event Public Class EventClass {Public Void Display (Object Sender, System.EventArgs E) {Console.Writeline; console.readline ();}} // Call class class invokeclass { // Declaration of the agent object, pay attention to the parameter public delegate void delegateObj (Object sender, system.eventargs e); // Declaration Event Object Private Event DelegateObj obj; // Declare the event class object to be called Private EventClass Ec; public invokeclass () { EC = New EventClass (); // Add event object to the event queue, parameter is the event this.obj = new delegateObj = new delegateObj (Ec.Display);} // call the delegate object Trigger event protected void OnoBJ (System.EventArgs e) {if (this.obj! = null) {OBJ (this, e);}} public void raiseevent ()} public void raiseevent ()}; onobj (e);} static void main (String [] args ) {Invokeclass (); console.writeline; string infut = console.readline (); if (INPUT.EQUALS (")) {Console.Writeline (" Sorry, you Don't Input Anything ");} else {// Trigger event ic.raiseevent ();}}}}

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

New Post(0)