Using ToOrder and ToDictionary
דוגמת שימוש למיון Dictionary.
נניח שיש לכם פונקציה שמחזירה Dictinoary
private static Dictionary<string, int> GetLeftTabsDefinition()
{
Dictionary<string, int> tabs = new Dictionary<string, int>()
{
{"ShowInfo", 2},
{"ShowResources", 1 },
{"ShowTOC", 3 },
};
return tabs;
}
כעת קבלתם את האובייקט
var tabs = GetLeftTabsDefinition();
ואתם רוצים למיין אותו - הקוד צריך להיראות כך.
tabs = tabs.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value);