Events in an interface
-
One simple question, if an event is declared like a field of delegate type, except that the keyword event precedes the event declaration how can an interface contain a type declaration? Jayant D. Kulkarni
-
One simple question, if an event is declared like a field of delegate type, except that the keyword event precedes the event declaration how can an interface contain a type declaration? Jayant D. Kulkarni
jdkulkarni wrote:
how can an interface contain a type declaration?
It can't. An interface can only contain signatures of the following members: Methods, Properties, Indexers and Events. (interface (C# Reference)[^]
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
-
jdkulkarni wrote:
how can an interface contain a type declaration?
It can't. An interface can only contain signatures of the following members: Methods, Properties, Indexers and Events. (interface (C# Reference)[^]
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
-
jdkulkarni wrote:
But I can not have delegate void MyDelegate(); but I can have event MyDelegate MyEvent; I am asking @ this scenario.
And you have (more or less) already answered yourself. The first is simply not possible, since an interface can only contain signatures of the following members: Methods, Properties, Indexers and Events; and this
delegate void MyDelegate();
declares a type that references a method.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook