generics - List.AddRange Has Some Invalid Arguments -


i want create list of flowers (for example) conform predefined iflower interface below.

public interface iflower {     string colour { get; }     int petals { get; } }  public class rose : iflower {     public rose()     {         string[] colours = new string[]{ "pink", "orange", "red", "crimson", "cerise" };         random random = new random();         colour = colours[random.next(0, 4)];     }      public string colour { get; set; }      public int petals     {         { return 8; }     } }  public class daisy : iflower{     public daisy()     {         string[] colours = new string[]{ "white", "yellow", "purple" };         random random = new random();         colour = colours[random.next(0, 2)];     }      public string colour { get; set; }      public int  petals     {         { return 18; }     } }  public class flowers {     public list<daisy> daisies     {                 {             list<daisy> items = new list<daisy>();             items.add(new daisy());             items.add(new daisy());             return items;         }     }      public list<rose> roses     {                 {             list<rose> items = new list<rose>();             items.add(new rose());             items.add(new rose());             return items;         }     } } 

the problem is, when run following code create concatenated list:

    public list<iflower> flowers     {                 {             list<iflower> output = new list<iflower>();             output.addrange(daisies);             output.addrange(roses);             return output;         }     } 

i error:

the best overloaded method match 'system.collections.generic.list<iflower>.addrange(system.collections.generic.ienumerable<iflower>)' has invalid arguments 

the roses , daisies tokens must each refer instance of class implementing

ienumerable<iflower> 

so guess 1 or both of them refers else.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -