null-coalescing collection literals #7349
-
There are quite a few circumstances where a method retrieves a list, but if that list is null we instead use an empty list. I was wondering if the current status of collection literals would allow a syntax like object[] m1 = M() ?? []; // Would this be legal?
var m2 = M() ?? []; // Maybe even interpreting the return type of M()?
static object[]? M() { /*...*/ } Sorry to rehash if this was explicitly discussed in the LDM, but that would be an extremely useful syntax for me. |
Beta Was this translation helpful? Give feedback.
Answered by
CyrusNajmabadi
Jul 17, 2023
Replies: 1 comment
-
Please discuss things related to collection literals in the collection literals discussion :) To answer your question. Both of those would be legal. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
RenderMichael
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please discuss things related to collection literals in the collection literals discussion :)
To answer your question. Both of those would be legal.