Reputation: 146
I have class Segment which has four instances of class PricingDetailPer
PricingDetailPerAdult
, PricingDetailPerChild
, PricingDetailPerSenior
, PricingDetailPerInfant
, and they all have property Availability
.
In code i need to get property Availability
but i need to check if Parent is exist. Is there shorthand like this:
return segment.PricingDetailPerAdult != null ? (this.Availability) : (continue checking);
where this
refers to segment.PricingDetailPerAdult
or some other property that i checking?
Upvotes: 0
Views: 317
Reputation: 78134
return segment.PricingDetailPerAdult?.Availability
?? segment.PricingDetailPerChild?.Availability
?? segment.PricingDetailPerSenior?.Availability
?? segment.PricingDetailPerInfant?.Availability;
Reference:
Null-conditional operators ?. and ?[]
?? operator
Upvotes: 2