如果?:
是左联想,那将意味着:
a ? b : c ? d : e
相当于:
(a ? b : c) ? d : e
代替:
a ? b : (c ? d : e)
将此应用于您的示例,您将获得:
string finalgrade = ( ( (grade > 90)
? "High Pass"
: (grade > 75))
? "Pass"
: (grade >= 60))
? "low pass"
: "fail";
其中——假设编译器没有抱怨不匹配的类型——forgrade = 100
将导致:
string finalgrade = ( ( true
? "High Pass"
: (grade > 75))
? "Pass"
: (grade >= 60))
? "low pass"
: "fail";
string finalgrade = ( "High Pass"
? "Pass"
: (grade >= 60))
? "low pass"
: "fail";
string finalgrade = "Pass"
? "low pass"
: "fail";
string finalgrade = "low pass";