First of all, it causes the stack overflow exception if you try to add
something to TestStatusChang ed. Because by the code below you simple
redefine the default "event" template behavior to add the value to
itself up to overflow exception.
public event TestStatus TestStatusChang ed
{
add { TestStatusChang ed += value; }
remove { TestStatusChang ed -= value; }
}
So, if you want your code to work then rewrite it just as:
public event TestStatus TestStatusChang ed;
or like:
class Test : ITest
{
private TestStatus _testStatus;
public event TestStatus TestStatusChang ed
{
add { _testStatus += value; }
remove { _testStatus -= value; }
}
}
But calling the _testStatus(..) , not the TestStatusChang ed(..) in this
case. Because it's what the "event" statement do behind
(
http://www.codeproject.com/useritems/howeventswork.asp).
Regards, Alex Meleta
Blog::
http://devkids.blogspot.com
-----Original Message-----
From:
hu*******@yahoo .com [mailto:hu****** *@yahoo.com]
Posted At: Montag, 30. April 2007 00:25
Posted To: microsoft.publi c.dotnet.langua ges.csharp
Conversation: Interface & Event
Subject: Interface & Event
I have an interface ITest that includes an event TestStatusChang e.
There is also a class Test that implements ITest. In one of the
functions of Test I want to call the event (see code at the end) but
get the following error:
"The event 'eventTest.Test .TestStatusChan ged' can only appear on the
left hand side of += or -=.
All samples I saw seem to do the same I am doing. What am I missing?
Thanks
using System;
using System.Collecti ons.Generic;
using System.Text;
namespace eventTest
{
public delegate void TestStatus(Stri ng status);
interface ITest
{
event TestStatus TestStatusChang ed;
}
class Test : ITest
{
public event TestStatus TestStatusChang ed
{
add { TestStatusChang ed += value; }
remove { TestStatusChang ed -= value; }
}
public void Check()
{
TestStatusChang ed("ok"); //!!!!!!!!! COMPILE
ERROR !!!!!!!!!!!!!
}
}
class Program
{
static void Main(string[] args)
{
}
}
}