Linked Questions
34 questions linked to/from Is it better to call ToList() or ToArray() in LINQ queries?
18 votes
3 answers
13k views
I need to iterate and count. What is fastest or preferred: ToArray() or ToList()? [duplicate]
Possible Duplicate: Is it better to call ToList() or ToArray() in LINQ queries? I have code like this: void Foobar(string[] arr, Dictionary<string, string[]>) { var t = arr.Intersect(dic....
17 votes
3 answers
10k views
C#: ToArray performance [duplicate]
Background: I admit I did not attempt to benchmark this, but I'm curious... What are the CPU/memory characteristics of the Enumerable.ToArray<T> (and its cousin Enumerable.ToList<T>)? ...
0 votes
2 answers
499 views
Which one is faster string[] or List<string> [duplicate]
Possible Duplicate: Is it better to call ToList() or ToArray() in LINQ queries? Hi, I have following code static void Main(string[] args) { const string FileName = @"c:\words"...
90 votes
5 answers
40k views
What interfaces do all arrays implement in C#?
As a new .NET 3.5 programmer, I started to learn LINQ and I found something pretty basic that I haven't noticed before: The book claims every array implements IEnumerable<T> (obviously, ...
70 votes
6 answers
21k views
Am I misunderstanding LINQ to SQL .AsEnumerable()?
Consider this code: var query = db.Table .Where(t => SomeCondition(t)) .AsEnumerable(); int recordCount = query.Count(); int totalSomeNumber = query.Sum(); decimal ...
52 votes
9 answers
25k views
FirstOrDefault() result of a struct collection?
So I've got a collection of structs (it's actually a WCF datacontract but I'm presuming this has no bearing here). List<OptionalExtra> OptionalExtras; OptionalExtra is a struct. public partial ...
28 votes
6 answers
23k views
Which one is more efficient : List<int> or int[]
Can someone tell me which one is more efficient between List<int> and int[]. Because I am working on a project and as you might know efficiency is way so important concern now. If you added ...
34 votes
7 answers
48k views
C# List<T>.ToArray performance is bad?
I'm using .Net 3.5 (C#) and I've heard the performance of C# List<T>.ToArray is "bad", since it memory copies for all elements to form a new array. Is that true?
26 votes
5 answers
63k views
Entity Framework with LINQ aggregate to concatenate string?
This is easy for me to perform in TSQL, but I'm just sitting here banging my head against the desk trying to get it to work in EF4! I have a table, lets call it TestData. It has fields, say: ...
23 votes
3 answers
22k views
Why am I getting "Collection was modified; enumeration operation may not execute" when not modifying the enumerated collection? [duplicate]
I have two collections of strings: CollectionA is a StringCollection property of an object stored in the system, while CollectionB is a List generated at runtime. CollectionA needs to be updated to ...
37 votes
1 answer
3k views
What changed in .net 5 that makes it not throw when changing dictionary values in foreach
In .NET<5 and .NET Core 3.1 the following code var d = new Dictionary<string, int> { { "a", 0 }, { "b", 0 }, { "c", 0 } }; foreach (var k in d.Keys) { d[k]+=...
10 votes
4 answers
2k views
Compare 2 byte arrays
I have 2 int arrays. int[] data1 # int[] data2 # I want to create a 3rd int[] data3 which is the differences between the 2 other arrays. Let us take the 1st value in data1. The value is 15 (e.g.). ...
7 votes
3 answers
5k views
Arrays vs Lists for memory issues
Since you need to input the length of an array at the time of creation, I assume that it requires a solid, continuous block of memory. A List can be dynamically expanded, so does this mean that it ...
1 vote
2 answers
2k views
LINQ to Entities: Orderby statement involving extension method
I'm constructing a simple search function for a site. The aim is to allow the user to find 'swimmers' and add them to a list via a search box, using a query like "bob staff". The first part of this I ...
0 votes
3 answers
1k views
Split an IEnumerable into multiple IEnumerables
I am new with linq, I need to split an IEnumerable of a type Couple(string text, bool indicator) to multiple IEnumerables based on the indicator, I tried with skipWhile and TakeWhile but I didn't find ...