4 ms·
No need to bounce between languages, you can get everything from C# : you call .Length on arrays but .Count on Lists but .Count() on IEnumerables ... It's a go
by jmnicolas 6y ago
No need to bounce between languages, you can get everything from C# : you call .Length on arrays but .Count on Lists but .Count() on IEnumerables ...
It's a good thing that Intellisense is top notch !
- asveikau 6y agoI guess there's no reason for a difference between .Length and .Count that I can think of. I guess you could make IEnumerable's Count() into a property and enjoy the same syntax but I am not sure it's a good idea, because Count() needs to enumerate and is therefore O(n), and property syntax may coax you into writing with the expectation that it is O(1). Then suddenly (it's been years since I did c#) I recall that Count() is added to the interface as an extension method with the "this" keyword. Is it possible to have an extension property? I do not think so but again it's been a while.