dynamic with ternary operator
问题 why and how this works in the below code dynamic x = ( c== 'a') ? new D1() :x= new D2(); but not this dynamic x = ( c== 'a') ? new D1() : new D2(); Code class Program { static void Main(string[] args) { var c = Console.ReadKey().KeyChar; dynamic x = ( c== 'a') ? new D1() :x= new D2(); x.Print(); Console.ReadKey(); } } class D1 { public void Print() { Console.WriteLine("D1"); } } class D2 { public void Print() { Console.WriteLine("D2"); } } 回答1: This has nothing to do with dynamic. This is