I use the Enumerable.Union<TSource> method to get the combination of Custom List1 with Custom List2. But for some reason this does not work, as it should be in my case. I receive all items and a duplicate once.
I followed the MSDN link to do this work, but still I cannot achieve the same.
The following is a custom class code: -
public class CustomFormat : IEqualityComparer<CustomFormat> { private string mask; public string Mask { get { return mask; } set { mask = value; } } private int type;
I call this the following: -
List<CustomFormat> l1 = new List<CustomFormat>(); l1.Add(new CustomFormat("#",1)); l1.Add(new CustomFormat("##",1)); l1.Add(new CustomFormat("###",1)); l1.Add(new CustomFormat("####",1)); List<CustomFormat> l2 = new List<CustomFormat>(); l2.Add(new CustomFormat("#",1)); l2.Add(new CustomFormat("##",1)); l2.Add(new CustomFormat("###",1)); l2.Add(new CustomFormat("####",1)); l2.Add(new CustomFormat("## ###.0",1)); l1 = l1.Union(l2).ToList(); foreach(var l3 in l1) { Console.WriteLine(l3.Mask + " " + l3.Type); }
Please suggest a suitable way to achieve the same!
c # linq extension-methods union
Joshi
source share