string s = null; Console.WriteLine(Convert.ToString(s));//1 Console.WriteLine(s);//2 Console.WriteLine(s.ToString());//3 - Why in the first case does not issue NULL reference?
- Why in the second case does not issue NULL reference? If I'm not mistaken, then in the Console.WriteLine () method, the .ToString () method is invoked to all variables explicitly.
- Why when explicitly specifying. ToString () returns a NULL reference?
You can link on these issues or keywords to find the necessary information.
Here is the il-code of the program:
IL_0000: nop IL_0001: ldnull IL_0002: stloc.0 IL_0003: ldloc.0 IL_0004: call string [mscorlib]System.Convert::ToString(string) IL_0009: call void [mscorlib]System.Console::WriteLine(string) IL_000e: nop IL_000f: ldloc.0 IL_0010: call void [mscorlib]System.Console::WriteLine(string) IL_0015: nop IL_0016: ldloc.0 IL_0017: callvirt instance string [mscorlib]System.Object::ToString() IL_001c: call void [mscorlib]System.Console::WriteLine(string) IL_0021: nop IL_0022: ret