worldfear
asked on
c# linq sort ienumberable enums
how do i use orderby on this:
Market m in Enum.GetValues(typeof(Mark et)).Cast< Market>()
??
so when i do this
foreach(Market m in Enum.GetValues(typeof(Mark et)).Cast< Market>())
{
DropDownList2.Items.Add(ne w ListItem(MarketUtil.GetDis playString (m), "0"));
}
the items are ordered?
Market m in Enum.GetValues(typeof(Mark
??
so when i do this
foreach(Market m in Enum.GetValues(typeof(Mark
{
DropDownList2.Items.Add(ne
}
the items are ordered?
Try changing:
marketValues.Sort();
foreach (var mValue in marketValues)
to:
foreach (var mValue in marketValues.Sort())
Otherwise, the .Sort() is not doing anything.
Gary Davis
marketValues.Sort();
foreach (var mValue in marketValues)
to:
foreach (var mValue in marketValues.Sort())
Otherwise, the .Sort() is not doing anything.
Gary Davis
ASKER
that didn't sort them - the order was the same.
an added complexity, i need the value of the enum as well (the int)
protected void DropDownList2_Init(object sender, EventArgs e)
{
//how do i sort these?
foreach(Market m in Enum.GetValues(typeof(Mark et)).Cast< Market>())
{
DropDownList2.Items.Add(ne w ListItem(MarketUtil.GetDis playString (m), ((int)m).ToString()));
}
}
an added complexity, i need the value of the enum as well (the int)
protected void DropDownList2_Init(object sender, EventArgs e)
{
//how do i sort these?
foreach(Market m in Enum.GetValues(typeof(Mark
{
DropDownList2.Items.Add(ne
}
}
ASKER
gardavis
for your suggestion - error
foreach cannot operate on variables of type void bc void isnt enumberable
for your suggestion - error
foreach cannot operate on variables of type void bc void isnt enumberable
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hey thanks i'll let you know monday!
Open in new window