title: remove duplicate from ObservableCollection<T>
body: <p>I have an <code>ObservableCollection&lt;DateTime&gt; myItems</code></p>
  
  <p>and it has some duplicate items that needs to be removed</p>
  
  <p>I tried using :</p>
  
  <pre><code>myItems = myItems.Distinct();
  </code></pre>
  
  <p>however i can't build it and recieve this error:</p>
  
  <blockquote>
    <p>Error 1   Cannot implicitly convert type
    'System.Collections.Generic.IEnumerable' to
    'System.Collections.ObjectModel.ObservableCollection'.
    An explicit conversion exists (are you missing a cast?)</p>
  </blockquote>
  
  <p>and when I check the ObservableCollection I find that it is <code>IEnumerable&lt;T&gt;</code> as the following Go to Definition shows:</p>
  
  <pre><code>public class ObservableCollection&lt;T&gt; : Collection&lt;T&gt;, INotifyCollectionChanged, INotifyPropertyChanged
  
  public class Collection&lt;T&gt; : IList&lt;T&gt;, ICollection&lt;T&gt;, IReadOnlyList&lt;T&gt;, IReadOnlyCollection&lt;T&gt;, IEnumerable&lt;T&gt;, IList, ICollection, IEnumerable
  </code></pre>
  
  <p>so I tried to cast as following :</p>
  
  <pre><code>myItems = (ObservableCollection&lt;DateTime&gt;) myItems.Distinct();
  </code></pre>
  
  <p>it build fine without error; but at runtime it throws the following error:</p>
  
  <blockquote>
    <p>An exception of type 'System.InvalidCastException' occurred in
    mscorlib.ni.dll but was not handled in user code Additional
    information: Unable to cast object of type
    'd__81<code>1[System.DateTime]' to type
    'System.Collections.ObjectModel.ObservableCollection</code>1[System.DateTime]'.</p>
  </blockquote>
  
  <p>I also tried the following:</p>
  
  <pre><code>myItems = (ObservableCollection&lt;DateTime&gt;) myItems.Distinct().toList&lt;DateTime&gt;();
  </code></pre>
  
  <p>but then I reeive the following compile time error:</p>
  
  <blockquote>
    <p>Error 1   Cannot convert type
    'System.Collections.Generic.List' to
    'System.Collections.ObjectModel.ObservableCollection'</p>
  </blockquote>
  
  <p>what I am missing here?
  and how can I remove the duplicate items from the ObservableCollection ?</p>