c# - Changing method from Dictionary to Struct -


i have method below use dictionary set 2 values nl. id , name/ key , value. understand dictionary can take two values, need change method can allow more values added type. best way this?

public dictionary<int, string> getquoteoptionlist(quoteoptiontype optiontype) {     dictionary<int, string> result = new dictionary<int, string>();      using (truckdb db = new truckdb())     {         switch (optiontype)         {             case quoteoptiontype.bodytype:                 db.bodytypes.tolist().foreach(x => result.add(x.id, x.name));                 break;                 ...             case quoteoptiontype.reardropside:                 db.reardropsides.tolist().foreach(x => result.add(x.id, x.name));                 break;             case quoteoptiontype.extras://example: (x.id, x.description, x.stockitem, x.minimumstock) add more 2 values                     db.extras.tolist().foreach(x => result.add(x.id, x.description));                     break;                 default:                     throw new argumentexception("the option selected not have corresponding list.");             }         }         return result;     } 

i have example in code on want changed , posted above this, check case quoteoptiontype.extras:

thank in advance or advice! :)

create class this:

public class yourclass {     public string id { get; set; }     public string description { get; set; }     public string stockitem { get; set; }     public string minimumstock { get; set; } }  list<yourclass> result = new list<yourclass>(); db.extras.tolist().foreach(c => result.add(new yourclass { id="id" , description="desc" , minimumstock="minimum" , stockitem="stock" })); 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -