Tag: r

60 votes
23 answers
2.8K views
How do I concatenate two arrays in C#?

int[] x = new int [] { 1, 2, 3}; int[] y = new int [] { 4, 5 }; int[] z = // your answer here... Debug.Asser

avatar
Suzan
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
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
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
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
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
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
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
57 votes
10 answers
991 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
838 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
53 votes
14 answers
907 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
57 votes
10 answers
2K views
Group by in LINQ

Let's suppose if we have a class like: class Person { internal int PersonID; internal string c

avatar
Omar
0 1 0 9
asked 07 September, 2021
62 votes
14 answers
1.3K views
Returning IEnumerable<T> vs. IQueryable<T>

What is the difference between returning IQueryable<T> vs. IEnumerable<T>, when should one be pref

avatar
Leonardo
0 1 0 9
asked 07 September, 2021
51 votes
7 answers
908 views
Multiple "order by" in LINQ

I have two tables, movies and categories, and I want to get an ordered list by categoryID first and then by Na

avatar
Carmelina
0 1 0 9
asked 07 September, 2021