Hi,
when I run the following code:
using System;
namespace ConsoleApplicat ion22
{
class Program
{
static void Main(string[] args)
{
BaseClass baseClass = new BaseClass();
BaseClass inheritedBaseCl ass = new InheritedClass( );
InheritedClass inheritedClass = new InheritedClass( );
baseClass.Event A += new EventHandler(ba seClass_EventA) ;
inheritedBaseCl ass.EventA += new
EventHandler(in heritedBaseClas s_EventA);
inheritedClass. EventA += new
EventHandler(in heritedClass_Ev entA);
Console.ReadLin e();
}
static void inheritedClass_ EventA(object sender, EventArgs e)
{
throw new Exception("The method or operation is not
implemented.");
}
static void inheritedBaseCl ass_EventA(obje ct sender, EventArgs
e)
{
throw new Exception("The method or operation is not
implemented.");
}
static void baseClass_Event A(object sender, EventArgs e)
{
throw new Exception("The method or operation is not
implemented.");
}
}
class BaseClass
{
public virtual event EventHandler EventA
{
add
{
this.EventB += this.BaseClass_ EventB;
this.EventC += this.BaseClass_ EventC;
}
remove
{
this.EventC -= this.BaseClass_ EventC;
this.EventB -= this.BaseClass_ EventB;
}
}
public virtual event EventHandler EventB;
public virtual event EventHandler EventC
{
add
{
}
remove
{
}
}
void BaseClass_Event C(object sender, EventArgs e)
{
throw new Exception("The method or operation is not
implemented.");
}
void BaseClass_Event B(object sender, EventArgs e)
{
throw new Exception("The method or operation is not
implemented.");
}
}
class InheritedClass : BaseClass
{
public override event EventHandler EventB
{
add
{
Console.WriteLi ne("EventB: Override add called");
}
remove
{
Console.WriteLi ne("EventB: Override remove called");
}
}
public override event EventHandler EventC
{
add
{
Console.WriteLi ne("EventC: Override add called");
}
remove
{
Console.WriteLi ne("EventC: Override remove called");
}
}
}
}
Then only the override of EventC will be called, not the one from
EventB. Was this to be expected?
Thx Karsten