tagged [linq-to-objects]

how to query LIST using linq

how to query LIST using linq Suppose if I add person class instance to list and then I need to query the list using linq. Now I want to query the above list with li

4 Feb at 15:13

Output a list/other data structure using linq query

Output a list/other data structure using linq query is there a way to do a Console.WriteLine() on a Generic Collection example: List a has: Is there a way to write out the List contents: Key, Value us...

7 Jul at 05:39

TakeWhile, but get the element that stopped it also

TakeWhile, but get the element that stopped it also I'd like to use the LINQ `TakeWhile` function on LINQ to Objects. However, I also need to know the first element that "broke" the function, i.e. the...

9 Jun at 15:30

why ForEach Linq Extension on List rather than on IEnumerable

why ForEach Linq Extension on List rather than on IEnumerable > [Why is there not a ForEach extension method on the IEnumerable interface?](https://stackoverflow.com/questions/101265/why-is-there-not-...

Find() vs. Where().FirstOrDefault()

Find() vs. Where().FirstOrDefault() I often see people using `Where.FirstOrDefault()` to do a search and grab the first element. Why not just use `Find()`? Is there an advantage to the other? I couldn...

15 Dec at 09:15

Sequence contains no elements exception in linq without even using Single

Sequence contains no elements exception in linq without even using Single I am not using `Single` in LINQ below, but I am still getting a 'Sequence contains no elements' exception: This e

Code equivalent to the 'let' keyword in chained LINQ extension method calls

Code equivalent to the 'let' keyword in chained LINQ extension method calls Using the C# compilers query comprehension features, you can write code like: In th

Basic array Any() vs Length

Basic array Any() vs Length I have a simple array of objects: I want to test if that method returns contacts. I really like the LINQ syntax for `Any()` as it highlights what I am trying to achieve: Ho...

18 Mar at 08:58

LINQ return items in a List that matches any Names (string) in another list

LINQ return items in a List that matches any Names (string) in another list I have 2 lists. 1 is a collection of products. And the other is a collection of products in a shop. I need to be able to ret...

28 Aug at 22:56

LINQ "MaxOrDefault"?

LINQ "MaxOrDefault"? I'm new to LINQ. I need to compute new_id as follows: Is there a LINQ way to compact that expression, so that I don't have to use the

2 May at 15:29

How to update an element with a List using LINQ and C#

How to update an element with a List using LINQ and C# I have a list of objects and I'd like to update a particular member variable within one of the objects. I understand LINQ is designed for query a...

Sorting a list using Lambda/Linq to objects

Sorting a list using Lambda/Linq to objects I have the name of the "sort by property" in a string. I will need to use Lambda/Linq to sort the list of objects. Ex: ``` public class Employee { public s...

27 Dec at 07:27

How can I get LINQ to return the object which has the max value for a given property?

How can I get LINQ to return the object which has the max value for a given property? If I have a class that looks like: And a collection of those items... How can I use LINQ to return the single "Ite...

6 Jul at 17:39

Lambda Expression for join

Lambda Expression for join ``` public class CourseDetail { public CourseDetail(); public string CourseId { get; set; } public string CourseDescription { get; set; } public long Cours...

18 Feb at 07:3

Whats the 'modern' way to find common items in two Lists<T> of objects?

Whats the 'modern' way to find common items in two Lists of objects? I have two Generic Lists containing different types, for the sake of example, lets call them `Products` and `Employees`. I'm trying...

26 Jul at 09:10

Use LINQ and C# to make a new List from an old List

Use LINQ and C# to make a new List from an old List This should be pretty simple, but I am new at LINQ. I have a `List` of `FillList` structs. I'd like to use LINQ to create a new `List` where instead...

15 Mar at 06:26

LINQ - is SkipWhile broken?

LINQ - is SkipWhile broken? I'm a bit surprised to find the results of the following code, where I simply want to remove all 3s from a sequence of ints: Why isn't 3 skipped? My next thought was, OK, t...

26 Mar at 22:2

Why does Enumerable.Empty() return an empty array?

Why does Enumerable.Empty() return an empty array? I expected the implementation of Enumerable.Empty() to be just this: But the implementation is something like this: ``` public static IEnumerable Emp...

12 Nov at 14:48

Like operator in LINQ to Objects

Like operator in LINQ to Objects I'm trying to emulate the `LIKE` operator in LINQ to Objects. Here my code: ``` List list = new List(); list.Add("line one"); list.Add("line two"); list.Add("line thre...

2 Nov at 17:43

Is there already a Conditional Zip function in c#?

Is there already a Conditional Zip function in c#? Is there already a function in C# that can perform a "Conditional Zip"? I.e. Is there a function that allows different length inputs and takes a pred...

Linq nested list expression

Linq nested list expression please I need your help with a Linq expression: I have nested objects with lists, this is how the main object hierarchy looks like (each dash is an atribute of the sub-clas...

26 May at 20:14

How to use async lambda with SelectMany?

How to use async lambda with SelectMany? I'm getting the following error when trying to use an `async` lambda within `IEnumerable.SelectMany`: > The type arguments for method 'IEnumerable System.Linq...

3 Nov at 09:48

OrderBy and Top in LINQ with good performance

OrderBy and Top in LINQ with good performance What is a good way to get the top 10 records from a very large collection and use a custom `OrderBy`? If I use the LINQ to Objects `OrderBy` method it is ...

Splitting an array using LINQ

Splitting an array using LINQ I have a collection uni-dimensional like this: I would like to convert that collection in a bi-dimensional collection like this: Basically I want to group or split if you...

28 Dec at 17:41

Does LINQ to Objects keep its order

Does LINQ to Objects keep its order I have a `List` and instead want to convert them for simple processing to a `List`, doing the following: Is the `.Select()` statement on a LINQ to Objects object to...

23 May at 12:10