【发布时间】:2011-10-29 13:25:01
【问题描述】:
我有这个代码:
_viewModel.PhoneDefault = user == null ? "" :
(string.IsNullOrEmpty(user.PhoneDay) ?
(string.IsNullOrEmpty(user.PhoneEvening) ?
(string.IsNullOrEmpty(user.Mobile) ? "" :
user.Mobile) :
user.PhoneEvening) :
user.PhoneDay);
有没有更好的方法来编写它以使其更具可读性?
【问题讨论】:
-
避免嵌套三元组肯定会让代码更具可读性
-
你考虑过使用“switch”吗?
标签: c# refactoring ternary-operator