Re:Kotlin Is Better
by Kipters on Thursday May 18, 2017 @04:23AM
(#14365654)
More often snippets like this can be even more straightforward:
[ Parent
| on HN ]
Except when you have to wrap it in parentheses and tack a .ToList() onto the end of it, or use something outside the subset that the query syntax supports, it starts looking considerably more ugly than chaining the functions together.
Re:Kotlin Is Better
by WorldMaker on Thursday May 18, 2017 @03:47PM
(#14370465)
The obvious answer is don't wrap a good query in parentheses, use a second line:
var somestuff = from x in someList
where x.Id > 7
select x.Name;
var somestuffList = somestuff.ToList();
For what it is worth, I personally consider ToList() harmful. I've done a lot of LINQ performance work and the first place I start is with a project-wide search for ToList and start to delete and/or replace calls to ToList to things more appropriate. List is more often than not the wrong data structure for a query result and I've seen too many people use ToList as a debugging crutch without understanding its performance impact.