[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1282
  • Last Modified:

Difference between observablecollection and inotifypropertychanged and INotifyCollectionChanged

Hi Friends,

Can you please help me in understanding

Difference between observablecollection and inotifypropertychanged and
'  INotifyCollectionChanged

Thankyou
0
N_Sri
Asked:
N_Sri
2 Solutions
 
Todd GerbertIT ConsultantCommented:
INotify... are both interfaces.  Classes that implement these interfaces must implement methods, properties and events that are described in the interface.  This allows code to be guaranteed of methods that an object supports.  For example, all objects that implement IDisposable are known to have a method named "Dispose" (because Dispose is defined in the interface).  That allows me to write a method that takes an IDisposable parameter, and I don't need to know or care if the object passed to my method is a Stream, database connection, etc - all I know is that this object implements IDisposable, therefore I know I can call .Dispose()
void someMethod(IDisposable someObject)
{
    someObject.Dispose();
}
ObservableCollection is a class that implements the two interfaces - it uses events to notify you when the contents of the collection it represents have changed.
http://msdn.microsoft.com/en-us/library/ms668604.aspx
http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx
http://msdn.microsoft.com/en-us/library/system.collections.specialized.inotifycollectionchanged.aspx 
0
 
ToddBeaulieuCommented:
Additionally,

Many of the UI controls are designed to be bound to a datasource that lets it know when rows are added, changed or removed. This is done via the INotifyCollectionChanged  interface. I suspect the inotifypropertychanged  interface in this case is used to signal changes to the collection property itself (like the Count property).

In your code you'll probably end up just using OCs, but framework and reusable code typically calls for a INotifyCollectionChanged  data source, because many data sources can implement this interface ... not just the OC. In fact, you could easily write your own class that implements this interface and can be bound to a UI control.
0
 
N_SriAuthor Commented:
thankyou
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now