How is null + true a string?

前端 未结 7 748
后悔当初
后悔当初 2021-01-30 05:49

Since true is not a string type, how is null + true a string ?

string s = true;  //Cannot implicitly convert type \'bool\' to \'string\         


        
7条回答
  •  萌比男神i
    2021-01-30 06:34

    var b = (null + DateTime.Now); // String
    var b = (null + 1);            // System.Nullable | same with System.Single, System.Double, System.Decimal, System.TimeSpan etc
    var b = (null + new Object()); // String | same with any ref type
    

    Crazy?? No, there must be a reason behind it.

    Someone call Eric Lippert...

提交回复
热议问题