【发布时间】:2020-11-22 02:02:51
【问题描述】:
我目前正在使用这种技术:
...
string s = user.Gender ? "Mr." : "Mrs.";
string body = $@"Dear {s} {user.First_name}..."
...
我想做这样的事情:
...
string body = $"Dear {return user.Gender ? "Mr." : "Mrs."} {user.First_name}..."
...
【问题讨论】:
-
对表达式使用括号:
$"Dear {(user.Gender ? "Mr." : "Mrs.")}"
标签: c# conditional-operator c#-6.0