using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var b = new ObservableCollection<int>();
b.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(b_CollectionChanged);
b.Add(100);
b.Add(100);
b.Add(100);
b[0] = 200;;
b[1] = 200;
/*输出100
200
100
200*/
Console.Read();
}
static void b_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (sender is ObservableCollection<int>)
{
ObservableCollection<int> t = sender as ObservableCollection<int>;
if (e.Action==System.Collections.Specialized.NotifyCollectionChangedAction.Add)
{
}
else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
{
}
else if (e.Action==System.Collections.Specialized.NotifyCollectionChangedAction.Move)
{
}
else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Replace)
{
foreach (var item in e.OldItems)
{
Console.WriteLine(item.ToString()); ;
}
foreach (var item in e.NewItems)
{
Console.WriteLine(item.ToString());
}
}
else
{
}
}
}
}
}