C# Language Design: explicit interface implementation of an event

Posted by ControlFlow on Stack Overflow See other posts from Stack Overflow or by ControlFlow
Published on 2010-02-15T18:27:06Z Indexed on 2010/05/06 7:38 UTC
Read the original article Hit count: 341

Small question about C# language design :))

If I had an interface like this:

interface IFoo {
  int Value { get; set; }
}

It's possible to explicitly implement such interface using C# 3.0 auto-implemented properties:

sealed class Foo : IFoo {
  int IFoo.Value { get; set; }
}

But if I had an event in the interface:

interface IFoo {
  event EventHandler Event;
}

And trying to explicitly implement it using field-like event:

sealed class Foo : IFoo {
  event EventHandler IFoo.Event;
}

I will get the following compiler error:

error CS0071: An explicit interface implementation of an event must use event accessor syntax

I think that field-like events is the some kind of dualism for auto-implemented properties.

So my question is: what is the design reason for such restriction done?

© Stack Overflow or respective owner

Related posts about c#

Related posts about design