I used to use .Except()
to compare the difference of two List in C# by using LINQ like following.
List<string> APromotionProduct= GetAPromotionProduct(PrdA);
List<string> BPromotionProduct = GetBPromotionProduct<string>(PrdB);
List<string> tempList = new List<string>();
tempList = PromotionProduct.Except(XMLPromotionProduct).ToList();
However, my company is not using LINQ, we are on .NET 3.
Therefore I can't use Enumerable.Except
. How can I achieve the same purpose
or how can I write the algorithm for .Except()
.
If you can't use LINQ for whatever reason, this is the source:
So you could use a
HashSet<string>
(ok, still .NET 3.5 needed):Then you can use:
If you are even on .NET 2: