Powiel możliwe:
C#: Passing null to overloaded method - which method is called?Pytanie CLR. Dlaczego metoda przeciążania w C# decyduje, że null jest ciągiem znaków?
Oto przypadek testowy
object a = null;
var b = Convert.ToString (null);
var c = Convert.ToString (a);
string d = Convert.ToString (null); // CLR chooses Convert.ToString(string value)
string e = Convert.ToString (a); // CLR chooses Convert.ToString(object value)
Powstaje pytanie, dlaczego CLR zdecyduje, że zerowa jest interpretowany jako ciąg w pierwszym przypadku? Wygląda na to, że na to pytanie już udzielono odpowiedzi here
Oto kolejny podobny przypadek. Żaden z tych funduszy inwestycyjnych są wyzwalane
object x = null;
if (x is object)
{
Console.Write ("x is object");
}
if (x is string)
{
Console.Write ("x is string");
}
if (null is object)
{
Console.Write ("null is object");
}
if (null is string)
{
Console.Write ("null is string");
}
Powiel możliwe: http://stackoverflow.com/questions/719546/c-passing-null-to-overloaded-method-which-method-is-called – CMS
Przypuszczam, czekamy aż Jon Skeet budzi się i oświeca nas na tej. –
On już ma, na łączu opublikowanym przez CMS. –