title: How to cast ObservableCollection<T> where T implements ISomething to IList<ISomething>
body: <p><a href="https://stackoverflow.com/questions/9005944/convert-listlistobject-to-ilistilistobject">convert List&lt;List&lt;object&gt;&gt; to IList&lt;IList&lt;object&gt;&gt;</a></p>
  
  <p><a href="https://stackoverflow.com/questions/9198876/does-enumerable-castt-copy-objects">Does Enumerable.Cast&lt;T&gt; Copy Objects?</a></p>
  
  <p><a href="https://msdn.microsoft.com/en-us/library/ms668604(v=vs.110).aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/ms668604(v=vs.110).aspx</a></p>
  
  <p><a href="https://msdn.microsoft.com/en-us/library/ms132397(v=vs.110).aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/ms132397(v=vs.110).aspx</a></p>
  
  <p>My class, Person, implements my interface, ISequenced.</p>
  
  <p>I have an ObservableCollection&lt;Person> which I need to pass to a method which takes as a parameter an object of type IList&lt;ISequenced>
  My question is how do I pass the ObservableCollection - without making a copy - such that the called function can modify it.</p>
  
  <p>Note that the answer to this question: <a href="https://stackoverflow.com/questions/3167752/is-there-a-way-to-convert-an-observable-collection-to-a-list">Is there a way to convert an observable collection to regular collection?</a>
  demonstrates .ToList() which creates a new object.</p>
  
  <pre><code>public interface ISequenced
  {
      int Sequence { get; set; }
  }
  
  
  public class Person : ISequenced
  {
      public int Sequence {get; set;}
      //...
  }
  
  public class MyCode
  {
      public ObservableCollection&lt;Person&gt; Entities {get; set;}
      public Person CurrentItem {get;set;}
  
  
      private void MoveDown()
      {
          IEnumerable&lt;ISequenced&gt; seq = Entities.Cast&lt;ISequenced&gt;(); // works but we need IList not IEnumerable
          IList&lt;Person&gt; p = (IList&lt;Person&gt;)Entities;                  //  works but we need IList ISequenced
          IList&lt;ISequenced&gt; pp = (IList&lt;ISequenced&gt;)p;                // throws
  
          // Need to pass a reference to Entities.... throws unable to cast here
          Sequencer.SequenceDown((IList&lt;ISequenced&gt;)Entities, CurrentItem as ISequenced);
  
      }
  }
  
  public static class Sequencer
  {
      public static void SequenceDown(IList&lt;ISequenced&gt; items, ISequenced currentItem)
      {
          // swap the positions of two elements in the collection here
      }
  }
  </code></pre>