Can't seem to get .Union to work (merging 2 array's together, exclude duplicates)
- by D. Veloper
I want to combine two array's, excluding duplicates. I am using a custom class:
public class ArcContact : IEquatable<ArcContact>
{
public String Text;
public Boolean Equals(ArcContact other)
{
if (Object.ReferenceEquals(other, null)) return false;
if (Object.ReferenceEquals(this, other)) return true;
return Text.Equals(other.Text);
}
public override Int32 GetHashCode()
{
return Text == null ? 0 : Text.GetHashCode();
}
}
I implemented and the needed IEquatable interface as mentioned in this msdn section. I only want to check the Text property of the ArcContact class and make sure an Array of ArcContact have an unique Text.
Here I pasted the code that I use, as you can see I have method with two parameters, array's to combine and below that the code I got from the previous mentioned msdn section.
internal static class ArcBizz
{
internal static ArcContact[] MergeDuplicateContacts(ArcContact[] contacts1, ArcContact[] contacts2)
{
return (ArcContact[])contacts1.Union(contacts2);
}
internal static IEnumerable<T> Union<T>(this IEnumerable<T> a, IEnumerable<T> b);
}
What am I doing wrong?