我真的不知道还有什么谷歌试图找到答案,任何人都可以告诉我实施这些事件的正确方法?在ClassOne事件被认为是空的,我只是不明白这一点....级联多继承和事件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MultipleInheritance
{
static class Program
{
static void Main()
{
ClassThree cThree = new ClassThree();
cThree.fireEventOne += cThree_fireEventOne;
cThree.Start();
cThree.Start2();
cThree.Start3();
}
static void cThree_fireEventOne()
{
Console.WriteLine("one two three");
}
}
}
,这里是班
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MultipleInheritance
{
public abstract class ClassOne
{
public delegate void EventOne();
public event EventOne fireEventOne;
public ClassOne()
{
}
public void Start()
{
fireEventOne();
}
public abstract void Start2();
}
public abstract class ClassTwo :ClassOne
{
public delegate void EventOne();
public event EventOne fireEventOne;
public override void Start2()
{
fireEventOne();
}
public abstract void Start3();
}
public class ClassThree :ClassTwo
{
public delegate void EventOne();
public event EventOne fireEventOne;
public override void Start3()
{
fireEventOne();
}
}
}
另请注意,C#实际上并没有多重继承,这就是类从同一级别的多个类继承的地方,比如'Child:Mother,Father'。你在做什么只是标准的继承。这只是“多重”,因为你有多个后代,但将其称为“多个”并不严格正确。 – 2014-11-24 23:48:03
啊,我c,谢谢=] – 2014-11-24 23:52:14