I have a model like this.
public class MenuItem
{
public string Description { get; set; }
public string MenuTypeID { get; set; }
public int DailyMax { get; set; }
}
Then I have a method like this.
public List<MenuItem> GetMenuItem()
{
List<MenuItem> menuItems = new List<MenuItem>();
DataSet ds = null;
.... left out ds populating code....
try
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
MenuItem menuItem = new MenuItemType();
menuItem.Description = dr["Description"].ToString();
menuItem.MenuTypeID = dr["MenuTypeID"].ToString();
menuItems.Add(menuItem);
}
List<MenuItemType> SortedList = menuItems.Sort((x, y) => x.MenuTypeID.CompareTo(y.MenuTypeID));
// compile error: Cannot implicitly convert type 'void' to 'System.Collections.Generic.List<MenuItem>'
}
catch (Exception ex)
{
}
finally
{
}
return SortedList;
}
My questions are,
- How to sort without the compile error?
- Is it possible to sort first by
menuTypeId
, then thedescription
?