首页 > 代码库 > C# 可观察集合
C# 可观察集合
1 static void Main() 2 { 3 var data = http://www.mamicode.com/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# 可观察集合
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。