C#への回答によると: オーバーロードされたメソッドに null を渡す - どのメソッドが呼び出されますか? 、ヌルは型情報を運ぶようです。実際、私も使用できます
class Program
{
static void Method(TypeA a)
{
Console.Write("Output of Method(TypeA a):");
Console.WriteLine(a); // Prints nothing, on account of the null.
}
static void Method(TypeB b)
{
Console.Write("Output of Method(TypeB b):");
Console.WriteLine(b); // Also prints nothing, on account of the null.
}
static void Main()
{
var a = (TypeA)null;
var b = (TypeB)null;
Method(a);
Method(b);
}
}
class TypeA { }
class TypeB { }
どの利回り
メソッドの出力 (TypeA a):
メソッドの出力 (TypeB b):
何が起きてる?