任何人都可以向我解釋當你使用三元運算符時幕後發生了什麼嗎? 沒有這行代碼:C中的三元運算符#
string str = 1 == 1 ? "abc" : "def";
作爲一個簡單的if/else語句產生的? 考慮以下幾點:
class A
{
}
class B : A
{
}
class C : A
{
}
現在使用三元表達式如下:
A a1 = 1 == 1 ? new B() : new C();
這還沒有與此錯誤編譯:
Type of conditional expression cannot be determined because there is no implicit conversion between 'ConsoleApp1.B' and 'ConsoleApp2.C'
任何人都可以揭示出這個一盞燈?
看看這個答案:http://stackoverflow.com/a/4290218/26396 – 2012-03-07 11:22:12
注意:這不是關於CLR,雖然它的*一個*三元運算符(以及唯一的運算符),運算符*名稱*是條件運算符。 – 2012-03-07 11:22:33