Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 25th, 2012  |  syntax: None  |  size: 0.58 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How can I pass a List<T> to another List of type that T implements
  2. public interface IRefDataItem
  3. {
  4.     int RefID { get; set; }
  5. string Code { get; set; }
  6. }
  7.  
  8. public class RACodeItem : IRefDataItem
  9. {
  10.     public int RefID { get; set; }
  11.     public string Code { get; set; }
  12. }
  13.        
  14. List<IRefDataItem> codes = GetRACodes( ); //GetRACodes returns List of RACodeItem
  15.        
  16. public interface ITest
  17. {
  18. }
  19.  
  20. public class Test1 : ITest
  21. {
  22. }
  23.  
  24. public class Test2 : ITest
  25. { }
  26.  
  27.  
  28. static void Main(string[] args)
  29. {
  30.     List<ITest> list = new List<Test1>();
  31.  
  32.     list.Add(new Test1());
  33.     list.Add(new Test2());
  34.  
  35. }