Use LINQ to concatenate multiple rows into single row (CSV property)

That’s the GroupBy operator. Are you using LINQ to Objects? Here’s an example: using System; using System.Collections.Generic; using System.Linq; public class Test { static void Main() { var users = new[] { new { User=”Bob”, Hobby=”Football” }, new { User=”Bob”, Hobby=”Golf” }, new { User=”Bob”, Hobby=”Tennis” }, new { User=”Sue”, Hobby=”Sleeping” }, new { User=”Sue”, … Read more

Calculate difference from previous item with LINQ

One option (for LINQ to Objects) would be to create your own LINQ operator: // I don’t like this name 🙁 public static IEnumerable<TResult> SelectWithPrevious<TSource, TResult> (this IEnumerable<TSource> source, Func<TSource, TSource, TResult> projection) { using (var iterator = source.GetEnumerator()) { if (!iterator.MoveNext()) { yield break; } TSource previous = iterator.Current; while (iterator.MoveNext()) { yield return … Read more

Can LINQ be used in PowerShell?

The problem with your code is that PowerShell cannot decide to which specific delegate type the ScriptBlock instance ({ … }) should be cast. So it isn’t able to choose a type-concrete delegate instantiation for the generic 2nd parameter of the Where method. And it also does’t have syntax to specify a generic parameter explicitly. … Read more

Standard Deviation in LINQ

You can make your own extension calculating it public static class Extensions { public static double StdDev(this IEnumerable<double> values) { double ret = 0; int count = values.Count(); if (count > 1) { //Compute the Average double avg = values.Average(); //Perform the Sum of (value-avg)^2 double sum = values.Sum(d => (d – avg) * (d … Read more

LINQ Join with Multiple Conditions in On Clause

You just need to name the anonymous property the same on both sides on new { t1.ProjectID, SecondProperty = true } equals new { t2.ProjectID, SecondProperty = t2.Completed } into j1 Based on the comments of @svick, here is another implementation that might make more sense: from t1 in Projects from t2 in Tasks.Where(x => … Read more

What’s the difference between IQueryable and IEnumerable [duplicate]

IEnumerable<T> represents a forward-only cursor of T. .NET 3.5 added extension methods that included the LINQ standard query operators like Where and First, with any operators that require predicates or anonymous functions taking Func<T>. IQueryable<T> implements the same LINQ standard query operators, but accepts Expression<Func<T>> for predicates and anonymous functions. Expression<T> is a compiled expression … Read more