c# - What should I store Weights in? -
i have weights(ounces, grams , etc) not sure how should handle them. @ first going use enum , give each 1 integer value , store value in database(using ef)
i thought idea can checks like
if(measurement.grams == userschoice) { // }
it restrict choices(ie if don't support "stones" fail if try set in enum),
i going convert enums array , display user ran 1 problem "fluid ounce". have display "fluidounce".
i use description property not sure if right way go.
option 1
use enum measurement
, dictionary<measurement, string>
map measurement
display name.
public enum measurement { grams, fluidounces, ... } private static dictionary<measurement, string> displayname = new dictionary<measurement, string> { { measurement.grams, "grams" }, { measurement.fluidounces, "fluid ounces" }, ... }; public static string displayname(measurement measurement) { return displayname[measurement]; }
option 2
use class measurement
has no public constructor, has public static readonly
instances, , has properties.
public class measurement { public string displayname { get; private set; } private measurement(string displayname) { this.displayname = displayname; } public static readonly measurement grams = new measurement("grams"); public static readonly measurement fluidounces = new measurement("fluid ounces"); ... }
Comments
Post a Comment