sqlserver教程网

当前位置: 主页 > 编程语言 > c# >

c#事件演示代码

时间:2019-01-10 11:31来源:www.sqlserver.net.cn 作者:admin 点击:
using System; using System.Threading; using System.Timers; using System.Collections; using System.Collections.Generic; namespace Consolehello { public delegate void callme(string s); class delegatetest { public event callme callmeyeah; publi
using System;
using System.Threading;
using System.Timers;
using System.Collections;
using System.Collections.Generic;

namespace Consolehello
{
    public delegate void callme(string s);
    class delegatetest
    {
        public event callme callmeyeah;

        public void callmeafter()
        {
        for(int i =0;i<=9;i++)
        {
            if (callmeyeah != null)
            {
                Thread.Sleep(1000);

                callmeyeah.Invoke("yes,it is" + i);
            }
        }

        }
    }
 

    class Program
    {

        static void Main(string[] args)
        {
            delegatetest t = new delegatetest();
            t.callmeyeah += CallMeBaby;
            t.callmeafter();
            Console.ReadKey();

        }

        static void CallMeBaby(string  s)
        {
            Console.WriteLine("call me baby one sec"+s);
        }
      
    
    }
} (责任编辑:admin)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
验证码: 点击我更换图片