0

I have dictionary like this :

   public Dictionary<string, string> fields
    {
          get
          { 
          }
          set
          {
          }
    }     

How can I fire event which will keep listening to this dictionary? And as soon as something is changed in the event some event handler should be called. Is it possible to do it without making this dictionary observable?

private int _age;
public event System.EventHandler AgeChanged;

protected virtual void OnAgeChanged()
{ 
 if (AgeChanged != null) AgeChanged(this,EventArgs.Empty); 
}

public int Age
{
 get
{
     return _age;
}

set
{
     _age=value;
     OnAgeChanged();
}
}

I don't want the above implementation.

Incredible
  • 3,495
  • 8
  • 49
  • 77
vish
  • 31
  • 1
  • 6

1 Answers1

1

You'll need a custom class. Wrap your dictionary in a class and create an event to track when the dictionary changes. You will need to override the existing add / remove etc and when they get called, have them raise your event.

Here's a good question that may help. .NET ObservableDictionary

Community
  • 1
  • 1
Aaron Palmer
  • 8,912
  • 9
  • 48
  • 77