Why Delegate become an Event???

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Why when instantiating a delegate the prefix “event†is added?

For example:

public delegate void ExampleDelegate(string str);

class example
{
....
public event ExampleDelegate DelegateMember;
....
}

If a drop the “event†prefix it's still working nicely, so why the “eventâ€
prefix is for???
 
I think the URL you posted explained it ok.
But it’s causing me some trouble:
When I wish to release my object that uses Remoting, I set the delegate to
null like that:

// Call this to set my handler upon the delegate
m_MyRemotingMarshal.SomeDelegate += new SomeDelegateType(My Method Handler);
// This is causing for a Compiler Error CS0070 that asks me to use -=
m_MyRemotingMarshal.SomeDelegate = null;

How should I use the -= instead the =null in the above example to avoid the
error?
 
Sharon said:
I think the URL you posted explained it ok.
But it?s causing me some trouble:
When I wish to release my object that uses Remoting, I set the delegate to
null like that:

// Call this to set my handler upon the delegate
m_MyRemotingMarshal.SomeDelegate += new SomeDelegateType(My Method Handler);
// This is causing for a Compiler Error CS0070 that asks me to use -=
m_MyRemotingMarshal.SomeDelegate = null;

How should I use the -= instead the =null in the above example to avoid the
error?

You can't set it to null - you can only remove an eventhandler, so just
use:

m_MyRemotingMarshal.SomeDelegate -= new SomeDelegate(MyMethodHandler);

to remove the one you've added before.
 
Back
Top