event accessor example - null?

  • Thread starter emma_middlebrook
  • Start date
E

emma_middlebrook

Hi

In MSDN, in the Using Events (C# Programming Guide), declaring event
accessors part it uses the following ...

But the lock will fail at the first call to add because
TestEventHandlers is null.

Any ideas how to fix this up? I can't just initialize the event with
something because it doesn't really make sense ...

private TestEventDelegate TestEventHandlers;

public event TestEventDelegate TestEvent
{
add
{
lock (TestEventHandlers)
{
TestEventHandlers += value;
}
}
remove
{
lock (TestEventHandlers)
{
TestEventHandlers -= value;
}
}
}

Cheers

Emma
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top