The study of C # learning-----re-commissioned

Source: Internet
Author: User
Tags textout

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;

Namespace ConsoleApplication7
{
public delegate void EH (string strText); //First step: Define a new delegate type (class)

Class Eventsourse
{
public event EH Textout;//Declare new delegate variable (instance variable)
public void Triggerevent ()
{
if (null! = Textout)
Textout ("Event triggered");//Third step: Call Delegate
}
}


Class TESTAPP
{
static void Main (string[] args)
{
Eventsourse evsrc = new Eventsourse (); Instantiate the EventSource class

Evsrc. Textout + = new EH (catchevent); ///Step two: Instantiate Evsrc. Textout----Delegate Catchevent static method to Ecsrc.textout (instance variable)
Evsrc.        Triggerevent (); ////Validation Delegate//call method catch on delegate's behalf

Evsrc. Textout-= new EH (catchevent);
Evsrc. Triggerevent ();

TESTAPP Theapp = new TestApp ();
Evsrc. Textout + = new EH (theapp.instancecatch);
Evsrc. Triggerevent ();
Console.read ();
}
public static void Catchevent (String strText)
{
Console.WriteLine (StrText);//Through TextOut (StrText), where strtext= "event triggered" call, catchevent, so output Event triggered
}
public void Instancecatch (string strText)
{
Console.WriteLine ("instance" + StrText);
}

}
}

The study of C # learning-----re-commissioned

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.