7 ms·
> if (customer?.Profile is not null) >{ > // Null-coalescing (??) > customer.Profile.Avatar = request.Avatar ?? "./default-avatar.jpg"; >} Isn't this ov
by billmcneale 1y ago
> if (customer?.Profile is not null)
>{
> // Null-coalescing (??)
> customer.Profile.Avatar = request.Avatar ?? "./default-avatar.jpg";
>}
Isn't this over engineered? Why not allow the assignment but do nothing if any of the intermediate objects is null (that's how Kotlin does it).
- LelouBil 1y agoThat's what's new in c#14, it allows you to do customer?.Profile?.Avatar = "thing" And will do nothing if the left hand side is null (not throw a null reference exception anymore)