score:5
Accepted answer
you can achieve this using linq:
double[] a = new double[]{1.0, 2.0, 3.0};
bool[] b = new bool[]{true, false, true};
var result = a.where((item, index)=>b[index]);
score:4
there's also this more traditional linq approach:
b.select((f, i) => f ? i : - 1).where(i => i != -1).select(i => a[i]);
score:6
use linq zip
method, e.g.:
a.zip(b, (i, j) => new {i, j}).where(x => x.j).select(x => x.i)
Source: stackoverflow.com
Related Query
- slicing array based on selection masks
- List or Array of String Contain specific word in Html Source Code
- Create a subset of an object based off an array of property names
- LINQ Source Code Available
- Generate dynamic LINQ expression based on array
- .NET 4 Code Contracts: "requires unproven: source != null"
- Explanation of Code : retrieve item from Array using FirstorDefault()
- C# get struct from array based on specific struct member value
- Querying Typescript array collection based on key
- creating Linq to sqlite dbml from DbLinq source code
- Trying to merge two string array based on comparision
- LINQ SUM data based on Array Results
- Create array of property values from list based on condition
- How can i copy data table records of different field name based on mapping list evaluating condition on source data table?
- C# find JSON value based only on Key name through multiple levels of array
- LINQ distinct selection based on a property value
- Fast selection of elements from a set, based on a property
- Array Intersection Based Upon A String Comparison
- Replacing an array item based on a property in the item
- LINQ with ManyToMany: Filtering based on multiple selection
- C# How to declare new Dictionary object based off a string array within a LINQ query
- Sum elements of the array based on index position, preferable with Linq
- Sorting Array based on property of object on inner array
- ConcurrentDictionary.Where very slow for filtering based int array (Key field)
- Creating an array then selecting based on it
- LINQ query - Multiple where with multiple sub queries based on int array
- source code for LINQ 101 samples
- How to sort string Array based on Number?
- c# Array Property based on other array
- How to do condition statement in LINQ based on code variables?
More Query from same tag
- How do I mimic the functionality of IQueryable<T>.Include(Expression<Func<T,TProperty>> path) in my custom collection?
- Extension Method with dynamically built linq predicate
- Anonymous Type with Lambda Expressions
- {"LINQ to Entities does not recognize the method 'Boolean IsLetter(Char)' method, and this method cannot be translated into a store expression."}
- How to replace a particular string in c# using regex or linq
- C# lambda get distinct list of value
- nested select projection with index in linq using EF Core
- LINQ with two groupings
- Reading the result of LINQ and XDocument
- The model backing the 'ApplicationDbContext' context has changed since the database was created
- Linq Distinct not bringing back the correct results
- The type or namespace name 'Linq' does not exist in the namespace 'System'
- Reading Complex XML Attributes
- In LINQ how to use column value passed to IQueryable function with func<T,T2>
- Linq Count inside Select, nested, minimizing immediate execution database dependency calls
- Get list of dates from StartDate to EndDate
- LINQ example code from microsoft...
- MVC: Using Mapping to change the model.SomeProperty type used in View
- In c# linq is it possible to assign value inside anonymous select
- EF4: Joining Entity Query on IEnumerable list of objects
- Convert this to VB .Net?
- Table contains particular value or not
- Linq join - group by - OrderByDescending query
- function returning object with max value
- Intersection of multiple lists with IEnumerable.Intersect()
- Complex LINQ query
- Foreach and Linq Statement Equalization
- LINQ update on joined collections
- query many to many relationship with Linq
- Executing stored procedures in parallel.foreach .net