C#字符串插值与条件算子

C#字符串插值与条件算子,c#,conditional-statements,string-interpolation,C#,Conditional Statements,String Interpolation,如果{condition}为false,如何在字符串中返回null。我正在使用带条件运算符的字符串插值 string returnURL=$“{condition?(ConfigurationManager.AppSettings[“ApplicationURL”]}/my page/{trip?.TripUId}):null”这样使用 bool flag = true; string returnUrl = flag ? $"{ConfigurationManager.AppSettings[

如果{condition}为false,如何在字符串中返回null。我正在使用带条件运算符的字符串插值

string returnURL=$“{condition?(ConfigurationManager.AppSettings[“ApplicationURL”]}/my page/{trip?.TripUId}):null”

这样使用

bool flag = true;
string returnUrl = flag ? $"{ConfigurationManager.AppSettings["ApplicationURL"]}/my-page{trip?.TripUid}" : null;

添加括号:
$“{(条件?…:)}”
我不清楚您想要实现什么。如果
条件
为false,是否希望
returnURL
本身为null?带有示例输入和输出的A将更容易帮助您。发送错误消息。(我怀疑您应该在插入的字符串文本之外使用条件运算符:
string returnUrl=condition?$“{ConfigurationManager.AppSettings[“ApplicationURL”]}/my page{trip?.TripUid}”:null;