using System;
using System.Windows.Forms;

public delegate void SampleEventHandler(string item);

public class Class1
{
    public event SampleEventHandler sampleEvent;

    public virtual void OnSampleEvent(string item)
    {
        if (sampleEvent != null)
        {
            sampleEvent(item);
        }
    }

    public static void runSampleEvent(string item)
    {
        MessageBox.Show(item);
        Console.WriteLine(item);
        Console.ReadLine();
    }

    static void Main()
    {
        Class1 class1 = new Class1();
        class1.sampleEvent += new SampleEventHandler(runSampleEvent);
        class1.OnSampleEvent("Hello world!");
    }
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
  • 2021-10-13
  • 2021-09-22
  • 2021-07-16
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-25
  • 2021-06-09
  • 2022-12-23
  • 2022-12-23
  • 2021-10-10
相关资源
相似解决方案