-
It is possible to pattern-match on an empty list/array/string/span/whatnot:
It is clear why this should remain unworkable for enumerables. But there is no technical reason this can't work for collections (ICollection, IReadOnlyCollection), which are frequently returned from calls. There is even guidance to do so. Currently, I get
which forces me to fall back to Thus, I suggest lifting this restriction in the particular case of an emptiness pattern. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
Closing as this is a request for a language change vs. being a compiler bug. Please open this as a discussion on dotnet/csharplang. |
Beta Was this translation helpful? Give feedback.
-
Duplicate of #6574 |
Beta Was this translation helpful? Give feedback.
-
I see that proposal #9005 would cover this request. However, the request here is quite doable and improves the outcome for code that follows published guidelines. Indeed I was surprised this case did not work OOTB. I often have code where the caller knows whether an empty collection just returned from somewhere is an error or needs to be handled differently. Having seen many careless "helpful helpers" to address this, I'd prefer a proper language idiom. Would you take patches? |
Beta Was this translation helpful? Give feedback.
I don't imagine much pushback, since the last LDM on this topic was "we still think we should finish this."