三項演算子を使用すると、舞台裏で何が起こるか教えてください。 のコード行はない: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'
誰もがこの1に光を当てることができます?
この回答を見る:http://stackoverflow.com/a/4290218/26396 –
注:これはCLRに関するものではなく、 a * 3項演算子(そして唯一のもの)は、演算子の* name *は条件演算子です。 –