Do you use null condition operators when getting values from objects
  v1.0 Posted at 29/01/2020 4:35 PM by Liam Elliott
​Null-conditional operators - makes checking for null as easy as inserting a single question mark. The Null-conditional operators feature boils down all of the previously laborious clunky code into a single question mark.

int length = customer != null && customer.name != null ? customer.name.length : 0;  

Figure: Bad Example - Verbose and complex code checking for nulls

int length = customers?.name?.length ?? 0;

​​Figure: Good Example - Robust and easier to read code

Related rules

    Do you feel this rule needs an update?

    If you want to be notified when this rule is updated, please enter your email address: