码迷,mamicode.com
首页 > Windows程序 > 详细

C# 可观察集合

时间:2016-10-18 13:37:34      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:

 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# 可观察集合

标签:

原文地址:http://www.cnblogs.com/farmer-y/p/5972712.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!