C# 可观察集合
Posted 指间的徘徊
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C# 可观察集合相关的知识,希望对你有一定的参考价值。
1 static void Main() 2 { 3 var data = new ObservableCollection<string>(); 4 data.CollectionChanged += Data_CollectionChanged; 5 data.Add("One"); 6 data.Add("Two"); 7 data.Insert(1, "Three"); 8 data.Remove("One"); 9 10 } 11 12 static void Data_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) 13 { 14 Console.WriteLine("action: {0}", e.Action.ToString()); 15 16 if (e.OldItems != null) 17 { 18 Console.WriteLine("starting index for old item(s): {0}", e.OldStartingIndex); 19 Console.WriteLine("old item(s):"); 20 foreach (var item in e.OldItems) 21 { 22 Console.WriteLine(item); 23 } 24 } 25 if (e.NewItems != null) 26 { 27 Console.WriteLine("starting index for new item(s): {0}", e.NewStartingIndex); 28 Console.WriteLine("new item(s): "); 29 foreach (var item in e.NewItems) 30 { 31 Console.WriteLine(item); 32 } 33 } 34 35 36 Console.WriteLine(); 37 38 }
以上是关于C# 可观察集合的主要内容,如果未能解决你的问题,请参考以下文章
C#编程(五十六)----------可观察的集合ObservableCollection