When I first encountered this situation, I decided to check my code, where I understand this. I tend to have two solutions, both of which are related to the null coalescing operator.
Case 1: Initialization. Using your values above, this will be:
object a = null ?? something;
Obviously, I would not write this line of code (resharper will complain if nothing else). But this is the essence of what is happening. If I have two (or more) values available when creating a , I write it like this:
Case 2: Never install a , but use ?? when a is used. In this case, the code will look like this:
MethodTakingA(a ?? b);
If there are several method calls or other places where I will need to use ?? then this is a bad idea.
There is a third case when I perform an exact task that you avoid. That is, when one of the parameters of my method can be null, and I have a default value for use in this case (as opposed to throwing an ArgumentNullException ). Here is an example:
public void Foo(string str) { str = str ?? String.Empty;
I would like to get a better answer for this case, but of course I do not write code where it is advisable to optimize this purpose, and the theoretical answer
string localStr = str ?? String.Empty;
Just adds a new variable to add it. Otherwise, I have nothing to do, so I maintain my self-name and live with it.