Get Alphabetical List Of Items in Collection Using Lambda/Linq?
c#, lambda, linq
Solution
Like this:
list.Select(o => o.DisplayName[0].ToString())
.Where(s => Char.IsLetter(s, 0))
.Distinct().ToList();
Edited
Problem
I have a list of objects. Each object contains a property called 'DisplayName'. I want to create another list of string objects, where each string represents the first letter or character (could be a number) in the DisplayName property for all objects in the initial list, and I want the list to be distinct. So, for example, if my list contained the following three objects: (1) DisplayName = 'Anthony' (2) DisplayName = 'Dennis' (3) DisplayName = 'John' I would want to create another list containing the following three strings: (1) 'A' (2) 'D' (3) 'J' Any idea how to do this with minimal coding using lambda expressions or linq?