我在以下代码中遇到错误,我指定了错误行 [英] I am getting error in the below code and i specified the error line

查看:73
本文介绍了我在以下代码中遇到错误,我指定了错误行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
namespace wildert
{
    public class Metronome
    {
        public event TickHandler Tick;
        public EventArgs e = null;
        public delegate void TickHandler(Metronome m, EventArgs e);
        public void Start()
        {
            while (true)
            {
                System.Threading.Thread.Sleep(3000);
                if (Tick != null)
                {
                    Tick(this, e);
                }
            }
        }
    }
        public class Listener
        {
            public void Subscribe(Metronome m)
            {
            m.Tick += new Metronome.TickHandler(HeardIt);//I am getting error here
            }
            private void HeardIt(Metronome m, EventArgs e)
            {
                System.Console.WriteLine("HEARD IT");
            }

        }
    class Test
    {
        static void Main()
        {
            Metronome m = new Metronome();
            Listener l = new Listener();
            l.Subscribe(m);
            m.Start();
        }
    }
}


错误是:错误1无法将类型"Event_Delegates.Metronome.TickHandler"隐式转换为"System.EventHandler"

谁能帮我.是的,我正在收到此错误,请在上面给出完整的代码段....


Erroe is:Error 1 Cannot implicitly convert type ''Event_Delegates.Metronome.TickHandler'' to ''System.EventHandler''

Can any one help me. Y i am getting this error ,i given the full code snippet please above....

推荐答案

您很困惑.这是行不通的.您无法在计时器上更改滴答事件的定义.计时器如何知道要通过什么?您需要做的是,连接一个正常的滴答事件,然后触发您想要的类型的事件,如果那是您想要的.您正在创建一种新类型的事件,并要求一个现有的类知道它是什么,但它不知道.
You are confused. This does not work. You can''t change the definition of the tick event on a timer. How does the timer know what to pass through ? What you need to do, is hook up a normal tick event, then fire an event of your type, if that''s what you want. You are creating a new type of event, and asking an existing class to know what it is, and it cannot know.


这篇关于我在以下代码中遇到错误,我指定了错误行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆