Is there a performance difference between null-check and null-conditional-operator in C#?

443 Views Asked by At

I am wondering whether there is a difference in performance between these two if-statements:

if(myObject != null && myObject.someBoolean)
{
    // do something
}

if (myObject?.someBoolean ?? false)
{
    // do something
}

If there is a difference in performance, in favor of which approach and why?

Edit: This is not a bottleneck in my application, I am not trying to over-optimize, I am simply curious.

1

There are 1 best solutions below

1
On

When the code will be compiled, both if-statements will be the same. You can easily check it with sharplab.io

Results