How to group on list of name with first letter?

public class ContactModel
{
    public string PeopleName { get; set; }
    public string PhoneNumber { get; set; }
}

List<ContactModel> contacts =new List<ContactModel>();

Contacts.Add(new ContactModel{PeopleName="Vijay Singh",PhoneNumber="9878987869"});
Contacts.Add(new ContactModel{PeopleName="Anuradha Patel",PhoneNumber="9878987869"});
Contacts.Add(new ContactModel{PeopleName="Binay Dixit",PhoneNumber="9878987869"});

I want to get a List<char> on Contact name First Letter like my list data => V,A,B

How to get this by LINQ in C#?

Simply you can do as follows:

var charList = contacts.Select(c => c.PeopleName.First()).ToList();

If you need Distinct first character list then do as follows:

var charList = contacts.Select(c => c.PeopleName.First()).Distinct().ToList();

BMDP Statistical Software, For GROUP the symbols plotted are the first letter of the group NAMES specified in slowest and group index moves fastest , as in the following list , for example​  While those informal greetings are fine for casual emails to friends or even for more formal emails you might send to groups of people, in a professional letter you'll need to use a personal salutation with either a first and/or last name ("Dear Mr. Doe") or a job title ("Dear Hiring Manager").

It is not quite clear whether you need Grouping or you just need the list of first characters.

Group By If you are looking at grouping based on First Characters, you could do the following.

var result = contacts.GroupBy(x=>x.PeopleName.First());

Your output would be as follows.

If you want to do the same case-insensitively, you could

var result = contacts.GroupBy(x=>x.PeopleName.First().ToString(),StringComparer.InvariantCultureIgnoreCase);

If you are looking for a List of first characters alone, you can do the following.

var result = contacts.GroupBy(x=>x.PeopleName.First()).Select(x=>x.Key);

Since you are grouping by First Letter, the duplicate keys wouldn't exist either eliminating the need to distinct as seen in some of your comments. Output for sample ,

BMDP Statistical Software Manual: To Accompany BMDP Release 7, EACH - Plot each group in a separate graph . list - The specified groups are plotted in the Use group names or numbers ( the order of the group in the CODES or symbol is the first letter from the NAMES specified in the GROUP paragraph . My first thought was to simply deal them out, as if they were playing cards or name tags. Below are the critical parts of the Plain English program I wrote to try that idea out.

Using LINQ's group ... by operator (or GroupBy() method), which manipulates a collection, and ToDictionary(), which converts an IEnumerable<T> to Dictionaty<T1, T2>, and ToList() method, which takes an IEnumerable<T> and returns a `List:

LINQ operators:

Dictionary<char, List<ContactModel>> = (from contact in Contacts
                                   group contact by contact.PeopleName[0])
                                   ).ToDictionary(g => g.Key, g => g.ToList());

LINQ methods:

Dictionary<char, List<ContactModel>> lst = Contacts.GroupBy(c => c.PeopleName[0])
                                       .ToDictionary(g => g.Key, g => g.ToList());

Best way to group String array by first character and show in Table , I can get list of all countries from iOS with Locale.isoRegionCodes and then getting localized name for users locale with But I got kind of stuck on creating groups by first letter and showing those in Table View. I cannot come  Find hundreds of names for boys and girls for every letter of the alphabet, and learn their meaning and origin. Browse by first letter to make that perfect monogram!

Pivotal Research in Early Literacy: Foundational Studies and , Using Names to Support Literacy Skills in a Whole-Group Context activities your name The letter clue game Name cards (all uppercase on one side; first letter over following 2 weeks; list of children's names (all uppercase) on chart stand  Search Names by Initial Letter. We have utilized the Latin alphabet to categorize the names; it consists of 26 characters from A to Z. This alphabet is used for names- in all over the world including English-speaking countries, Spanish-speaking countries and Portuguese-speaking countries, you can search for a name by initial letter.

Access 2007 Bible, For instance, you can choose to group by only the first character of a field field, a group header and footer appears for the set of all customers whose name begins The Grouping intervals list box displays different values for the various data  You also need to group by just the first character of the first_name. Something like this should work: SELECT SUBSTR(first_name, 1, 1) AS alpha, COUNT(*) AS employee_count FROM employees GROUP BY SUBSTR(first_name, 1, 1); That would group by the first letter of the first name, and show the number of employees that fall into that group.

Group By Expression, This will be demonstrated in this example where the employee list will be grouped by the first letter of the employee last name. An expression will be developed  In Microsoft Office Word 2003 and in earlier versions of Word, point to Letters and Mailings on the Tools menu, and then click Mail Merge Wizard. In Microsoft Office Word 2007, click Start Mail Merge in the Start Mail Merge group on the Mailings tab, and then click Step by Step by Mail Merge Wizard. Under Select document type, click Letters.

Comments
  • var results = Contacts.GroupBy(x => x.PeopleName[0]).ToList();
  • suppose the list return a,b,a,n,m so how to distinct this with this same linq statement?
  • The query returns a two dimensions array : results[key][ContactModel[]]
  • suppose the list return a,b,a,n,m so how to distinct this with this same linq statement?
  • how to find the list item with matching first Char in linq?