Tag: c

62 votes
9 answers
1.5K views
How to perform .Max() on a property of all objects in a collection and return the object with maximum value

I have a list of objects that have two int properties. The list is the output of another linq query. The

avatar
Dario
0 1 0 9
asked 07 September, 2021
62 votes
23 answers
2.2K views
Entity Framework. Delete all rows in table

How can I quickly remove all rows in the table using Entity Framework? I am currently using: var rows = from o

avatar
Boyd
0 1 0 9
asked 07 September, 2021
61 votes
16 answers
714 views
How would you do a "not in" query with LINQ?

I have two collections which have property Email in both collections. I need to get a list of the items in the

avatar
Wei
0 1 0 9
asked 07 September, 2021
51 votes
12 answers
1.6K views
Deserializing JSON to .NET object using Newtonsoft (or LINQ to JSON maybe?)

I know there are a few posts about Newtonsoft so hopefully this isn't exactly a repeat...I'm trying

avatar
Clarice
0 1 0 9
asked 07 September, 2021
55 votes
11 answers
1.2K views
Remove duplicates in the list using linq

I have a class Items with properties (Id, Name, Code, Price). The List of Items is populated with duplicated

avatar
Winford
0 1 0 9
asked 07 September, 2021
45 votes
7 answers
647 views
What does LINQ return when the results are empty

I have a question about LINQ query. Normally a query returns a IEnumerable<T> type. If the return is emp

avatar
Thurman
0 1 0 9
asked 07 September, 2021
54 votes
5 answers
823 views
Flatten List in LINQ

I have a LINQ query which returns IEnumerable<List<int>> but i want to return only List<int>

avatar
Dario
0 1 0 9
asked 07 September, 2021
63 votes
17 answers
3K views
Using LINQ to concatenate strings

What is the most efficient way to write the old-school: StringBuilder sb = new StringBuilder(); if (strings.C

avatar
Lashawna
0 1 0 9
asked 07 September, 2021
56 votes
4 answers
1.1K views
Convert Linq Query Result to Dictionary

I want to add some rows to a database using Linq to SQL, but I want to make a "custom check" before adding the

avatar
Kurtis
0 1 0 9
asked 07 September, 2021
52 votes
11 answers
2.2K views
C# LINQ find duplicates in List

Using LINQ, from a List<int>, how can I retrieve a list that contains entries repeated more than once an

avatar
Cortez
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
60 votes
22 answers
994 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
1.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