Resolved: Initialize a value when not null (or leave the default if new value is null)

In this post, we will see how to resolve Initialize a value when not null (or leave the default if new value is null)

Question:

If I have an object, that has defaults defined so they are not null
When I want to create a new instance, and initialize the values
Is there a clean way to assign the value to SomeList only if myListThatMightBeNull isn’t null, and leave the default value otherwise?
Doing this obviously works, it just feels clunky compared to other modern syntax.
Is there some sort of backwards =?? operator?

Best Answer:

You can use the null coalescing ?? operator while assigning this list. On the Microsoft website, you can find its documentation here
so you code will be as following:
or if you need to use inline initialisation use empty list as default callback

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com