Consider you have a set of string names: Chin, Rahul, and John. And you would like to build a comma separated string from the collection. We can do this using the Aggregate extension in LINQ as follows:
IEnumerable<string> sList = new List<string> {"Chin", "Rahul", "John"}; var commaSeparated = sList.Aggregate((x, y) => x + "," + y); var pipeSeparated = sList.Aggregate((x, y) => x + "|" + y);
Here is the expected output:
Chin,Rahul,John Chin|Rahul|John
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
General News Suggestion Question Bug Answer Joke Praise Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.