If you can't use LINQ for whatever reason, this is the source:
static IEnumerable<TSource> ExceptIterator<TSource>(IEnumerable<TSource> first, IEnumerable<TSource> second, IEqualityComparer<TSource> comparer) {
Set<TSource> set = new Set<TSource>(comparer);
foreach (TSource element in second) set.Add(element);
foreach (TSource element in first)
if (set.Add(element)) yield return element;
}
So you could use a HashSet<string>
(ok, still .NET 3.5 needed):
public static IEnumerable<TSource> ExceptNoLinq<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
{
HashSet<TSource> set = new HashSet<TSource>(comparer);
foreach (TSource element in second) set.Add(element);
foreach (TSource element in first)
if (set.Add(element)) yield return element;
}
Then you can use:
var exceptItems = PromotionProduct.ExceptNoLinq(XMLPromotionProduct);
List<string> resultList = new List<string>(exceptItems);
If you are even on .NET 2:
public static IEnumerable<TSource> ExceptDotNet2<TSource>(this IEnumerable<TSource> first, IEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
{
var dict = new Dictionary<TSource, bool>(comparer);
foreach (TSource element in second) dict.Add(element, true);
foreach (TSource element in first)
{
if (!dict.ContainsKey(element))
{
dict.Add(element, true);
yield return element;
}
}
}