4 ms·
Though that will result in a lot more calls to Count(). A let would fix that.
by cmircea 13y ago
Though that will result in a lot more calls to Count(). A let would fix that.
- voltagex_ 13y agoI really really really should learn more Linq. Where would I use let, and why?
- cmircea 13y agofrom word in text.Split(' ') group word by word into g let count = g.Count() orderby count descending select g.Key Under the covers when it is compiled it's turned into a select. That way it it only does N counts, not potentially N log N (for each comparison in the orderby), where N is the number of items you enumerate (so if you .Take() just 10 it doesn't really matter).
- louthy 13y agoIndeed! It wouldn't be quite as concise though, which was kind of my point :)