Is there any difference between using LinQ to filter compared to using a collections Where() method.
More specifically,
First
var numQuery = from num in numbers
where (num % 2) == 0
select num;
Second
var numQuery = numbers.Where(num => num % 2 == 0);
In the above query, which is better? And is there any performance consideration?
Thanks.
There is no difference. The first one is the
Query TypeLINQ. The second one is theExtension Methodtype. I’ll prefer the second one because it has many built-in functionalities.from the link below
MSDN: LINQ Query Syntax versus Method Syntax (C#)