static List <object> SortObjectByCount(List <object> LetterAndCounts) { List <object> sortedByCount = (from LetterAndCount in LetterAndCounts orderby LetterAndCount.GetType().GetProperty("Count").GetValue(LetterAndCount) descending select LetterAndCount).ToList(); return(sortedByCount); }
static List <object> SortObjectByLetter(List <object> LetterAndCounts) { List <object> sortedByLetter = (from LetterAndCount in LetterAndCounts orderby LetterAndCount.GetType().GetProperty("Letter").GetValue(LetterAndCount).ToString().ToLower() select LetterAndCount).ToList(); return(sortedByLetter); }
static void DisplayLetterAndCounts(List <object> LetterAndCounts) { foreach (object LetterAndCount in LetterAndCounts) { char letter = (char)LetterAndCount.GetType().GetProperty("Letter").GetValue(LetterAndCount); int letterCount = (int)LetterAndCount.GetType().GetProperty("Count").GetValue(LetterAndCount); Console.WriteLine($"{ letter }: { letterCount }"); } }