C#没有与委托匹配的重载,如下面我打*的地方,为何必须有(object source, ElapsedEventArgs e)才不报错?
usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Timers;names...
using System;
using System.Collections.Generic;
using System.Text;
using System.Timers;
namespace tryout
{
public class Class1
{
static void Main(string[] args)
{
Timer t = new Timer();
t.Elapsed += OnTimedEvent;
t.Interval = 1000;
t.Enabled = true;
Console.Read();
}
private static void OnTimedEvent()*****
{
Console.Clear();
Console.WriteLine(DateTime.Now);
}
} 展开
using System.Collections.Generic;
using System.Text;
using System.Timers;
namespace tryout
{
public class Class1
{
static void Main(string[] args)
{
Timer t = new Timer();
t.Elapsed += OnTimedEvent;
t.Interval = 1000;
t.Enabled = true;
Console.Read();
}
private static void OnTimedEvent()*****
{
Console.Clear();
Console.WriteLine(DateTime.Now);
}
} 展开
1个回答
展开全部
事件处理方法写错了,改成
priavate static void OnTimedEvent(object sender, ElapsedEventArgs e)
{
Console.Clear();
Console.WriteLine(DateTime.Now);
}
更多追问追答
追问
是不是因为委托声明的时候就有参数(object sender, ElapsedEventArgs e),所以必须在引用的方法里有(object sender, ElapsedEventArgs e)?
追答
对,正是这个原因!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询