My number format in C# is not giving me a padded number -
My number format in C# is not giving me a padded number -
i using following:
public static selectlist getoptions<t>(string value = null) t : struct { var values = enumutilities.getspacedoptions<t>(); var options = new selectlist(values, "value", "text", value); homecoming options; } public static ienumerable<selectlistitem> getspacedoptions<t>(bool zeropad = false) t : struct { var t = typeof(t); if (!t.isenum) { throw new argumentexception("not enum type"); } var numberformat = zeropad ? "d2" : "g"; var options = enum.getvalues(t).cast<t>() .select(x => new selectlistitem { value = ((int) enum.toobject(t, x)).tostring(numberformat), text = regex.replace(x.tostring(), "([a-z])", " $1").trim() }); homecoming options;
my enum has values:
public enum defaultstatus { release = 0, review = 1, inprogress = 2, concept = 3, none = 99 };
from understand number format should give values of "01","02" etc it's giving me ""1","2","3" ..
is there obvious i'm doing wrong?
your getspacedoptions
has optional parameter zeropad
default value false
.
use
var values = enumutilities.getspacedoptions<t>(true);
instead of
var values = enumutilities.getspacedoptions<t>();
c#
Comments
Post a Comment