3 ms·
.length is easier. .length, .size, .len, .count, then all those again but as functions taking an array argument, then again but as method calls, are not. And t
by spanhandler 6y ago
.length is easier.
.length, .size, .len, .count, then all those again but as functions taking an array argument, then again but as method calls, are not. And that’s not all the possibilities!
Seriously I bounce between languages enough that I have to look this shit up every time if autocomplete doesn’t help me out, and even that might take a couple tries.
- jmnicolas 6y agoNo 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.
- thewebcount 6y agoAnd on top of all that, it doesn't tell you the units of the result. Is it size in characters? Size in bytes? Size in code points? (Obviously in 1989, it was both characters and bytes, but these days, who knows?)