public static IEnumerableSubtract (IEnumerable source, IEnumerable other) { return Subtract(source, other, EqualityComparer .Default); } public static IEnumerable Subtract (IEnumerable source, IEnumerable other, IEqualityComparer comp) { Dictionary dict = new Dictionary (comp); foreach(T item in source) { dict[item] = null; } foreach(T item in other) { dict.Remove(item); } return dict.Keys; }
參考資料:
http://stackoverflow.com/questions/2266682/how-to-substract-one-generic-list-from-another-in-c2-0
備註:C#預設交集操作:
http://msdn.microsoft.com/zh-tw/library/bb460136.aspx
沒有留言:
張貼留言