分配非空值的最短方式

huangapple go评论59阅读模式
英文:

Shortest way to assign a not null value

问题

这只是在值不为 null 时分配一个值。如果为 null,则不分配任何值。

英文:

I have a long list of code similiar to the following. Is there a way to shorten this?

 pallete.ActionDefault = themeInfo.ActionDefault is not null ? themeInfo.ActionDefault : pallete.ActionDefault;

This just assigns a value if it is not null. If it is null, do not assign any value.

答案1

得分: 1

只使用 ?? 进行空值检查。x = y ?? z

英文:
only use ?? for null check. x = y ?? z

huangapple
  • 本文由 发表于 2023年1月9日 12:50:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75053294.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定