public string b() { string b = ""; string c = "1313131"; return b == "" ? "0" : b + c != "" ? c : "0";//结果是0 } public int c() {
public string b() { string b = ""; string c = "1313131"; return (b == "" ? "0" : b) + (c != "" ? c : "0");// } public int c() { return (3 == 4 ? 3 : 4 )+ (3 != 4 ? 3 : 4);// }
}
这个需要考虑的是优先级的问题,正确的写法是,在每个三元表达外面写上一个小括号,这样结果才正确