score:11
Accepted answer
An alternative solution with using SelectMany
(it keeps the duplicates):
var combined = list.Where(c => c.Flag)
.SelectMany(c => new[] { c.Present, c.Previous });
Assert.AreEqual(4, combined.Count());
score:0
Does the final ordering of the strings in the list matter? If not, it seems like this would be the clearest way to accomplish this:
var strings = new List<String>();
foreach (var value in list.Where(c => c.Flag))
{
strings.Add(value.Present);
strings.Add(value.Previous);
}
Source: stackoverflow.com
Related Query
- Combine the results of two columns in a select into one array with LINQ?
- How can I combine this code into one or two LINQ queries?
- C# Combine two lists with nested lists into one using LINQ
- Use LINQ to compare two lists, and produce a third one with results from one OR the other
- LINQ Comparing two list and putting the results into one list
- simplifying two queries into one with the same types linq
- How to combine the results of two DTOs in C# into one list of one type
- linq combine results from two tables to one select new statment?
- Combining The Results Of Two Linq Queries Into A Single Var?
- linq how to select a parent with a child collection that contains one or many of an array (or list) of values
- Left join on two Lists and maintain one property from the right with Linq
- Merge two Lists in C# and merge objects with the same id into one list item
- How do I combine multiple linq queries into one results set?
- C# LINQ Select objects with the same value of one property join values of other
- How to convert list of objects with two fields to array with one of them using LINQ
- How to use LINQ to combine two or more collections into one collection
- How can I use linq to select the columns of a jagged array
- Is possible with LINQ to extract from an array of objects the value of one property and create a new array?
- How to select multiple columns from dataset into a string list with LinQ
- Is there a way to combine these two LINQ statements into one
- Select two columns from the table via linq
- Unable to combine two linq results in one var
- Convert SQL IN clause with two columns into LINQ
- combine 2 queries from the same table into one linq query
- VB.Net Linq with datatables - select from one table what does not exist in the other
- Insert Record into two tables with one to many relation by using linq to ado.net entity froamwork
- NHibernate Linq with subquery returns 'Only one expression can be specified in the select list when the subquery is not introduced with EXISTS'
- C# Linq with datatables - select from one table what does not exist in the other
- Combine Two Entities Into One Using LINQ
- How can I do a LINQ query joining two entities and select what a Where on one of the entities?
More Query from same tag
- How use Long type for Skip in Linq
- Use delegate for Projection in Linq to SQL
- Find maximum depth/level of a nested collection
- LINQ query to call instance method
- Linq Expression - How to initialize with Expression.And properly?
- Flatten List in LINQ
- Linq Where clause with dynamic conditions
- Use LINQ instead of foreach
- Deleting bulk objects in DataContext
- linq multiple field search
- how to add conditional join in linq?
- Dynamic values in linq query by other field and boolean value
- Get this Join query result with EF Core?
- linq predicate remove objects from collection issue
- Linq to SQL Date conversion error
- Is PLinq Inherently Faster than System.Threading.Tasks.Parallel.ForEach
- Add object to a BindingList in a BindingList
- Run variable number of LINQ queries asynchronously
- LINQ query on DataTable - Could not find an implementation of the query pattern
- Linq To Sql: Relations not correctly updated
- How to Linq DbContext with Array or list having flexible length
- Get html tags embedded in xml using linq
- Where condition in Razor DropdownList MVC
- Compare a Datatable and string array in c#
- Linq outer Join
- Finding common elements within a list of objects
- Pick the matching result between 2 lists using LINQ
- Are there any connections between Haskell and LINQ?
- Group by in LINQ on a property in an array
- Select max value in dropdownlist?