c# - Efficient way to pass large number of argments into a constructor -


i working on project , have object, upon instantiation of which, have large number of values (20+) passed it. know make constructor take in of values, looking cleaner / more efficient way this.

just put in perspective, object character in game, new instances of created. values assigned attributes randomly generated.

is constructor large number of arguments best way go? or there better way don't know about? advice appreciated.

edit: when new game starts, list<character> created , loop creates 10 instances of character , adds them list.

you can create call defines game character. have users populate class , pass argument class.

something this,

public class charecterinfo {         public string name {get;set;}        public int power {get;set;}        public int health{get;set;} }  public class charecter {       public charecter(charecterinfo charecterinfo)      {         //import values      } } 

i avoid using public properties, since class used while it's not initialized (in bad state) job of constructor. should use constructor , validate input before allowing user continue.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -