Could we have a count operator? #4398
Replies: 4 comments 6 replies
-
Sounds like a lot of complexity for very little utility. Having to explicitly specify the member you want to reference builds on existing language semantics and puts the control in the hands of the developer, which is good thing especially when |
Beta Was this translation helpful? Give feedback.
-
Recent LDM meetings have raised the question of whether to introduce a "length pattern" as part of the list patterns feature. This suggestion seems related. https://github.com/dotnet/csharplang/blob/master/meetings/2020/LDM-2020-12-16.md#list-patterns For example, if a length pattern were introduced to the language, it might become possible to say something like I'm pretty fuzzy on where the LDM is currently with this concept more recently, so take with a grain of salt, as I'm referring to something that's in the early stages of design. |
Beta Was this translation helpful? Give feedback.
-
One more data point: the fact that Rider IDE offers both Length and a Count autocomplete options for collections, but then self-corrects the choice of Length to Count, says something about this odd, yet all too common area in c#. I stumble across this all the time. There are numerous scenarios where I change a data structure from a list to an array (or vice-versa), and the fact that this property now becomes a compile error just feels like something I shouldn't have to worry about. |
Beta Was this translation helpful? Give feedback.
-
Obligatory xkcd: We've got |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is it
Length
? Or is itCount
? Or is itCount()
? Who cares!?Wouldn't it be nice if we could do something like:
?
Beta Was this translation helpful? Give feedback.
All reactions