c# - storing multiple possibilities in settings -
i have scenario cant work out best way approach in head, want give me maximum extendability , avoid magic number coding.
essentially simplified example this.
user inputs number (lets 5326) system round number down or nearest "acceptable value" comes list. want list configurable. note also, different variables have different lists e.g.
acceptableheight: 1000,2000,3000,4000 acceptablelength: 500,600,700,800
the best way can think store values this:
<appsettings> <add key="acceptableheight" value="1000,2000,3000,4000" /> <add key="acceptablelength" value="500,600,700,800" /> </appsettings>
the logic can think of is
- get value config
- split comma list of integers
- sort list (just in case)
- some sort of search find nearest value (or use end values)
but not 100% sure how...
you can store string , parse suggested.
int[] acceptableheight = appsetting["acceptableheight"].split(',').select(x => int.parse(x));
Comments
Post a Comment