你如何执行if then else语句作为连接?

时间:2014-07-22 18:03:14

标签: c# if-statement

例如:

StringBuilder list1 = new StringBuilder();
StringBuilder list2 = new StringBuilder();


sb.Append("alert('Operation has been submitted, however, the following files were not valid and thus operations against their respective courses were not processed: "
 + if x == 1 display list1.ToString() else if x==2 display list2.ToString() +
". An email will be sent when the process has completed for any applicable valid course IDs.");

这甚至可能吗?

1 个答案:

答案 0 :(得分:13)

使用Ternary Operator

string message = x == 1 ? "message1" : x == 2 ? "message2" : "message3"