I've seen answers mentioning something compact like this:here
List<T> withDupes = LoadSomeData();
List<T> noDupes = withDupes.Distinct().ToList();
So I tried the following (syntax)
List<InfoControl> withDupes = (List<InfoControl>)listBox1.ItemsSource;
listBox1.ItemsSource = withDupes.Distinct().ToList();
but withDupes is null ? Perhaps I am retrieving the wrong data list. I added InfoControls one at a time.
Is there something else I should be implementing in InfoControl class? (Equal,hashCode)?
Thanks Addendum 1: [ignore I should not be translating from Java :) ] Also have (translated from a Java example, not sure it's 100% correct) declared in the InfoControl class..
public Boolean Equals(Object obj) 
{ if (obj == this) { return true; } 
if (!(obj is InfoControl)) { return false; } 
InfoControl other = (InfoControl)obj; 
return this.URL.Equals(other.URL); } 
public int hashCode() 
{ return this.URLFld.Content.GetHashCode(); } 
Addendum 2: When I try to use override based on the msdn link custom type example it says it is sealed :) It does not seem distinct is stepping thru GetHashCode() and I am still getting the same listbox.items.count after distinct.
bool IEquatable<InfoControl>.Equals(InfoControl other)
{
if (Object.ReferenceEquals(other, null)) return false;
if (Object.ReferenceEquals(this, other)) return true;
return URL.Equals(other.URL);
}
public int GetHashCode(InfoControl obj)
{
     return obj.URL.GetHashCode();
}
Addendum 3: When I try override VS2010 says it is sealed? "cannot override inherited member 'System.Windows.DependencyObject.GetHashCode()' because it is sealed" what am I doing wrong?
  public override int GetHashCode()
    {
        return URL.GetHashCode();
    }
   public string URL
    {
        get { return this.URLFld.Content.ToString() ; }
        set
        {
            this.URLFld.Content = value;
        }
    }
. Addendum 4:
   public partial class InfoControl : UserControl
         , IEquatable<YouTubeInfoControl>
    {
        private string URL_;
        public string URL
        {
            get { return URL_; }
            set
            {
                URL_ = value;
            }
        }
        bool IEquatable<YouTubeInfoControl>.Equals(YouTubeInfoControl other)
        {
            if (Object.ReferenceEquals(other, null)) return false;
            if (Object.ReferenceEquals(this, other)) return true;
            return URL == other.URL;
        }
        public override int GetHashCode()
        {
            return URL.GetHashCode();
        }
    }
 
     
     
    