Hello Everyone my problem is when i add the data to Dictionary in c# and i want to switch (Sortype) string to check how the user wants the order data like this:
string SortType="ByDownloads";
Dictionary<string, Data> WorldInfo = JsonConvert.DeserializeObject<Dictionary<string, Data>>(Res.Body.ToString());
switch (SortType)
{
case "ByDownloads":
WorldInfo.OrderByDescending(AllData => AllData.Value.PostDownloads).ToList();
break;
case "ByViews":
WorldInfo.OrderBy(AllData => AllData.Value.PostViews).ToList();
break;
}
In this way, the code Will Not work and the Data does not sorted but when i use this way the code will work:
Dictionary<string, Data> WorldInfo = JsonConvert.DeserializeObject<Dictionary<string, Data>>(Res.Body.ToString());
var NewSortedDictionary = WorldInfo.OrderByDescending(AllData => AllData.Value.PostViews).ToList();
So I'm looking for the right way to do it and use (WorldInfo) Dictionary and switch (SortType) then i use it instead of (NewSortedDictionary). Thank you :)