c# - Cannot implicitly convert type 'System.Collections.Generic.List<Library.Product>' to 'System.Collections.Generic.List<Library.IHierarchicalEntity>' -


possible duplicate:
in c#, why can't list<string> object stored in list<object> variable

i having following code.

   public class manufacturer :  ihierarchicalentity     {         public string manufacturername         {                         {                 return _manfuacturername;             }             set             {                 _manfuacturername = value;             }         } private string _manfuacturername;          public list<product> products         {                         {                 return _products;             }         } private list<product> _products;          #region ihierarchicalentity members          public list<ihierarchicalentity> children         {                         {                 return products; //this compiler error             }         }          #endregion     }      public class product :  ihierarchicalentity{}      public interface ihierarchicalentity     {         list<ihierarchicalentity> children { get; }     } 

i compiler exception

cannot implicitly convert type system.collections.generic.list<library.product> system.collections.generic.list<library.ihierarchicalentity>

both manufacturer , product of type ihierarchicalentity. why not taking list<product> list<ihierarchicalentity> ?

this conversion not possible, otherwise add otherhierarchicalentity list<product> not safe. can cast explicitly , return new list:

  return products.cast<ihierarchicalentity>().tolist(); 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -