Re: how to wrap your brain around delegates?
- From: "Joanna Carter [TeamB]" <joanna@xxxxxxxxxxxx>
- Date: Mon, 12 Jun 2006 19:28:54 +0100
"Peter Morris [Droopy eyes software]" <pete@xxxxxxxxxxxxxxxxxxxxxx> a écrit
dans le message de news: 448dae05@xxxxxxxxxxxxxxxxxxxxxxxxx
| I thought that events were multi-cast, not delegates. A delegate is just
a
| method signature declaration.
Well, this is where I am a bit flummoxed. You have to declare an event if
you are declaring a property, but you can simply declare a field of the
delegate type to support that property.
e.g.
public class NotificationEventArgs : EventArgs
{
private object aspect;
public NotificationEventArgs(object aspect)
{
this.aspect = aspect;
}
public object Aspect
{
get { return aspect; }
}
}
public delegate void NotificationHandler(object sender,
NotificationEventArgs args);
public class SubjectImplementer
{
private NotificationHandler notify;
public void OnNotify(object sender, object aspect)
{
if (notify != null)
{
NotificationEventArgs args = new NotificationEventArgs(aspect);
notify(sender, args);
}
}
public event NotificationHandler Notify
{
add { notify += value; }
remove { notify -= value; }
}
}
So the field is treated as multicast by the property !! ??
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer
.
- Follow-Ups:
- Re: how to wrap your brain around delegates?
- From: Craig Stuntz [TeamB]
- Re: how to wrap your brain around delegates?
- References:
- how to wrap your brain around delegates?
- From: Bryce K. Nielsen
- Re: how to wrap your brain around delegates?
- From: Joanna Carter [TeamB]
- Re: how to wrap your brain around delegates?
- From: Peter Morris [Droopy eyes software]
- how to wrap your brain around delegates?
- Prev by Date: Re: Delphi outsourcing is gone ?
- Next by Date: Re: What is object oriented programming?
- Previous by thread: Re: how to wrap your brain around delegates?
- Next by thread: Re: how to wrap your brain around delegates?
- Index(es):
Relevant Pages
|