Tag: linq

57 votes
12 answers
1.9K views
What is the difference between IQueryable<T> and IEnumerable<T>?

What is the difference between IQueryable<T> and IEnumerable<T>? See also What's the differe

avatar
Jesenia
0 1 0 9
asked 07 September, 2021
55 votes
6 answers
2K views
LINQ .Any VS .Exists - What&apos;s the difference?

Using LINQ on collections, what is the difference between the following lines of code? if(!coll.Any(i => i

avatar
Virgil
0 1 0 9
asked 07 September, 2021
56 votes
4 answers
2.2K views
LINQ Orderby Descending Query

I'm sure this will be a relatively simple one. I have a LINQ query that I want to order by the most rece

avatar
Sena
0 1 0 9
asked 07 September, 2021
59 votes
10 answers
1.9K views
Join/Where with LINQ and Lambda

I'm having trouble with a query written in LINQ and Lambda. So far, I'm getting a lot of errors here

avatar
Leonardo
0 1 0 9
asked 07 September, 2021
60 votes
19 answers
2K views
How to use LINQ to select object with minimum or maximum property value

I have a Person object with a Nullable DateOfBirth property. Is there a way to use LINQ to query a list of Pe

avatar
Alba
0 1 0 9
asked 07 September, 2021
51 votes
16 answers
2.1K views
LINQ: When to use SingleOrDefault vs. FirstOrDefault() with filtering criteria

Consider the IEnumerable extension methods SingleOrDefault() and FirstOrDefault() MSDN documents that SingleO

avatar
Corrin
0 1 0 9
asked 07 September, 2021
60 votes
22 answers
990 views
Retrieving Property name from lambda expression

Is there a better way to get the Property name when passed in via a lambda expression? Here is what i currentl

avatar
Robyn
0 1 0 9
asked 07 September, 2021
55 votes
16 answers
1.4K views
Is it better to call ToList() or ToArray() in LINQ queries?

I often run into the case where I want to eval a query right where I declare it. This is usually because I nee

avatar
Adolfo
0 1 0 9
asked 07 September, 2021
57 votes
16 answers
2.6K views
Update all objects in a collection using LINQ

Is there a way to do the following using LINQ? foreach (var c in collection) { c.PropertyToSet = value; }

avatar
Robyn
0 1 0 9
asked 07 September, 2021
55 votes
23 answers
1K views
LEFT OUTER JOIN in LINQ

How to perform left outer join in C# LINQ to objects without using join-on-equals-into clauses? Is there any w

avatar
Tuan
0 1 0 9
asked 07 September, 2021
58 votes
12 answers
2.9K views
Concat all strings inside a List<string> using LINQ

Is there any easy LINQ expression to concatenate my entire List<string> collection items to a single str

avatar
Alba
0 1 0 9
asked 07 September, 2021
61 votes
10 answers
2.8K views
Use LINQ to get items in one List<>, that are not in another List<>

I would assume there's a simple LINQ query to do this, I'm just not exactly sure how. Given this pi

avatar
Luis
0 1 0 9
asked 07 September, 2021
49 votes
10 answers
1.2K views
Which method performs better: .Any() vs .Count() > 0?

in the System.Linq namespace, we can now extend our IEnumerable's to have the Any() and Count() extension

avatar
Luis
0 1 0 9
asked 07 September, 2021
60 votes
20 answers
3.1K views
Dynamic LINQ OrderBy on IEnumerable<T> / IQueryable<T>

I found an example in the VS2008 Examples for Dynamic LINQ that allows you to use a sql-like string (e.g. Orde

avatar
Patsy
0 1 0 9
asked 07 September, 2021
58 votes
14 answers
532 views
Using LINQ to remove elements from a List<T>

Say that I have LINQ query such as: var authors = from x in authorsList where x.firstname == "B

avatar
Lawanda
0 1 0 9
asked 07 September, 2021
57 votes
10 answers
987 views
IEnumerable vs List - What to Use? How do they work?

I have some doubts over how Enumerators work, and LINQ. Consider these two simple selects: List<Animal>

avatar
Eddie
0 1 0 9
asked 07 September, 2021
58 votes
12 answers
834 views
LINQ Aggregate algorithm explained

This might sound lame, but I have not been able to find a really good explanation of Aggregate. Good means s

avatar
Fabian
0 1 0 9
asked 07 September, 2021
60 votes
22 answers
2.8K views
LINQ equivalent of foreach for IEnumerable<T>

I'd like to do the equivalent of the following in LINQ, but I can't figure out how: IEnumerable<

avatar
Yolando
0 1 0 9
asked 07 September, 2021
60 votes
14 answers
3K views
When to use .First and when to use .FirstOrDefault with LINQ?

I've searched around and haven't really found a clear answer as to when you'd want to use .Firs

avatar
Sena
0 1 0 9
asked 07 September, 2021
53 votes
14 answers
903 views
Group By Multiple Columns

How can I do GroupBy multiple columns in LINQ Something similar to this in SQL: SELECT * FROM <TableName>

avatar
Nereida
0 1 0 9
asked 07 September, 2021