Can't seem to get .Union to work (merging 2 array's together, exclude duplicates)

Posted by D. Veloper on Stack Overflow See other posts from Stack Overflow or by D. Veloper
Published on 2010-03-30T08:00:12Z Indexed on 2010/03/30 8:03 UTC
Read the original article Hit count: 259

Filed under:
|
|
|
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about arrays