Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between List.All() and List.TrueForAll()

Tags:

c#

linq

Is there a practical difference between .All() and .TrueForAll() when operating on a List? I know that .All() is part of IEnumerable, so why add .TrueForAll()?

like image 593
Bobson Avatar asked Feb 11 '11 14:02

Bobson


2 Answers

From the docs for List<T>.TrueForAll:

Supported in: 4, 3.5, 3.0, 2.0

So it was added before Enumerable.All.

The same is true for a bunch of other List<T> methods which work in a similar way to their LINQ counterparts. Note that ConvertAll is somewhat different, in that it has the advantage of knowing that it's working on a List<T> and creating a List<TResult>, so it gets to preallocate whatever it needs.

like image 96
Jon Skeet Avatar answered Nov 18 '22 14:11

Jon Skeet


TrueForAll existed in .NET 2.0, before LINQ was in .NET 3.5.

See: http://msdn.microsoft.com/en-us/library/kdxe4x4w(v=VS.80).aspx

like image 11
Daniel A. White Avatar answered Nov 18 '22 14:11

Daniel A. White