Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
230 views
in Technique[技术] by (71.8m points)

regarding ObservableCollection in c#

i found a piece of code that use ObservableCollection but they can use list or any other collection related classes. can anyone tell me what is the benifit of using ObservableCollection.

ObservableCollection<Employee> empData = new ObservableCollection<Employee> 
        {
            new Employee{Name="Diptimaya Patra", Contact="0000", 
                EmailID="diptimaya.patra@some.com", Country="India"},
            new Employee{Name="Dhananjay Kumar", Contact="00020", 
                EmailID="dhananjay.kumar@some.com", Country="India"},
            new Employee{Name="David Paul", Contact="1230", 
                EmailID="david.paul@some.com", Country="India"},
            new Employee{Name="Christina Joy", Contact="1980", 
                EmailID="christina.joy@some.com", Country="UK"},
            new Employee{Name="Hiro Nakamura", Contact="0000", 
                EmailID="hiro.nakamura@some.com", Country="Japan"},
            new Employee{Name="Angela Patrelli", Contact="0000", 
                EmailID="angela.patrelli@some.com", Country="Japan"},
            new Employee{Name="Zoran White", Contact="0000", 
                EmailID="diptimaya.patra@some.com", Country="Scotland"},
        };

please discuss in detail. thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The benefit of ObservableCollection is that it raises the CollectionChanged event every time the collection is changed, and the PropertyChanged event every time one of the properties of the collection is changed.

In a similar way, if you want an object (which is not a collection) to raise an event every time one of its properties change, you should make it implement INotifyPropertyChanged.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...