Is there an “opposite” to the null coalescing operator? (…in any language?)

后端 未结 12 1086
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 18:38

null coalescing translates roughly to return x, unless it is null, in which case return y

I often need return null if x is null, otherwise return x

12条回答
  •  忘掉有多难
    2020-12-04 19:19

    This is being added in C# vNext (Roslyn powered C#, releases with Visual Studio 2014).

    It is called Null propagation and is listed here as complete. https://roslyn.codeplex.com/wikipage?title=Language%20Feature%20Status

    It is also listed here as complete: https://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/3990187-add-operator-to-c

提交回复
热议问题