我有这样的代码:嵌套三元运营商
_viewModel.PhoneDefault = user == null ? "" :
(string.IsNullOrEmpty(user.PhoneDay) ?
(string.IsNullOrEmpty(user.PhoneEvening) ?
(string.IsNullOrEmpty(user.Mobile) ? "" :
user.Mobile) :
user.PhoneEvening) :
user.PhoneDay);
有没有更好的方式来写这使其更具可读性?
避免嵌套ternaries必将使代码更易读一行内 – kjetilh
你有没有考虑过使用“开关”? –