c# - Call a non-default constructor in from a generic list instantiation -


i have class called fred constructor takes parameter parma want pass initialisation of generic list of type multictorclass called mylist.

the default constructor multictorclass passes parmb base; want call other constructor of multictorclass passing in parma initialisation of fred.

public class fred {     public fred(parmtype parma)     {         mylist = new list<multictorclass>();     }      public ienumerable<multictorclass> mylist { get; set; } }  public class multictorclass : mybase {     public multictorclass()         : this(parmb)     {     }      public multictorclass(parmtype parm)         : base(parm)     {     } } 

i trying following:

    public fred(parmtype parma)     {         mylist = new list<multictorclass(parma)>();     } 

how can achieved?

you're not calling constructor in either case - list empty. call constructor when creating new item, e.g.

mylist.add(new multictorclass(...)); 

and can pick constructor @ there :)


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -