score:0
Accepted answer
You can use Aggregate:
options.Aggregate((current, next) => current + ", " + next);
Note that this generates a new string for each operation, so if your options list is long you are better off using an old school approach with StringBuilder
score:3
While Aggregate
will work it has O(n2) performance. If you need better performance you can use string.Join
. Unfortunately this method doesn't accept an IEnumerable<string>
so you have to also use ToArray
to get what you want:
string.Join(", ", options.Select(o => o.Name).ToArray())
Source: stackoverflow.com
Related Query
- linq subquery child collection to string
- LINQ to EF - Find records where string property of a child collection at least partially matches all records in a list of strings
- linq select items from child collection
- Collection to string using linq
- Linq extension method, how to find child in collection recursive
- linq how to select a parent with a child collection that contains one or many of an array (or list) of values
- LINQ - filter child collection
- LINQ WHERE method alters source collection
- using LINQ how can i concatenate string properties from itesm in a collection
- Order parent collection by minimum values in child collection in Linq
- Joining parent and child collection in LINQ for a single merged output
- LINQ Source Code Available
- NHibernate querying on a string collection using Linq results in either error or empty collection
- How to use LINQ to filter property of child collection using (.Any())
- linq how to select the parent from a collection where the parent contains child items in another collection
- How to filter child collection with linq dynamic
- How do I query a collection of objects in LINQ by a child property?
- C# linq query filter child Collection
- How do I delete records from a child collection in LINQ to SQL?
- creating Linq to sqlite dbml from DbLinq source code
- linq filtering child collection
- How to select by child collection value in LINQ
- Linq - Select single item from child collection
- Filter Linq Child Collection by another List/Array
- SQL subquery result in LINQ and Entity Framework Code First
- Filter Parent Collection Using Criteria in Child Collection via a Linq Query
- linq to entities changing database connection string in code
- Linq Search Principle and child collection with OR statement
- MongoDB Linq nested Child Collection
- How to order a collection with LINQ so that a particular string appears first
More Query from same tag
- How can I get every nth item from a List<T>?
- Trying to map a property of an object to a string with AutoMapper
- Aggregate values at hourly interval using LINQ C#
- How to compare only dates in linq?
- adding index to linq query result
- Membership.GetUser() within TransactionScope throws TransactionPromotionException
- How to include counted property in a query and rename the column in the result in c#
- LEFT OUTER JOIN 2 datatables
- LINQ to SQL querying same column multiple times
- Creating Nested Groupings using Linq Extension Methods
- C# Driver- LINQ - Aggragate - Contains in Int[]
- Linq Concat to Lazy-Load it's contents
- Get value in foreach-loop
- Array of array combinations
- Convert T-SQL into LINQ Lambda
- Assigning rows evenly from table
- Calculate difference from previous item with LINQ
- How to remove a node while preserving its value and child nodes?
- High Level Function Confusion with Lambda/LINQ expressions in C#
- Check if single() LINQ return NULL
- LINQ select all items of all subcollections that contain a string
- Data in Linq query not in join is not in output to json only those that are related in 2 classes are showing up
- What can I do to resolve a "Row not found or changed" Exception in LINQ to SQL on a SQL Server Compact Edition Database?
- How to construct overlaps DbExpression in EF
- How to get a list which contains at least all the values of another list?
- Fatal Error Encountered using LINQ and mysqlconnection
- How to convert a number to a range of prices
- LINQ searching a List that contains a Class with objects
- Grouping Data with LINQ Not Working
- Linq to return only selected columns from table