c# - Address custom enum values by order -
usually can address each item in enum it's ordered position (0, 1, 2, 3...), if i've created enum custom values (as below), there still way address each item declared order (e.g., off
= 0, _5m
= 1, _15m
= 2, etc.), rather value?
enum waittime { off = 0, _5m = 5, _15m = 15, _30m = 30, _1h = 60, _2h = 120, _3h = 180, _6h = 360, _12h = 720, _1d = 1440, _2d = 2880 }
in c# can use enum.getvalues()
method.
it retrieves array of values of constants in specified enumeration. elements of array sorted binary values of enumeration constants.
array enumelementsinarray = enum.getvalues(typeof(waittime)); int firstelement = enumelementsinarray[0]; int secondelement = enumelementsinarray[1];
but know that, return aray after sorting elements values. of course, enum work want.
Comments
Post a Comment