三元运算符 c# shorthand

Ternary operator c# shorthand

我有 class 段,其中有四个实例 class PricingDetailPer PricingDetailPerAdultPricingDetailPerChildPricingDetailPerSeniorPricingDetailPerInfant, 他们都有 属性 Availability.

在代码中我需要获取 属性 Availability 但我需要检查 Parent 是否存在。有没有这样的shorthand:

return segment.PricingDetailPerAdult != null ? (this.Availability) : (continue checking);

其中 this 是指 segment.PricingDetailPerAdult 还是我正在检查的其他 属性?

return segment.PricingDetailPerAdult?.Availability
       ?? segment.PricingDetailPerChild?.Availability
       ?? segment.PricingDetailPerSenior?.Availability
       ?? segment.PricingDetailPerInfant?.Availability;

参考:

Null-conditional operators ?. and ?[]
?? operator