Cosa stampa a console il seguente snippet e perché?:
using
System;
class
Foo
{
public
Foo(out Foo foo)
{
foo =
this;
throw
new Exception();
}
}
class
Test
{
static
void Main()
{
Foo
f = null;
try
{ f = new Foo(out
f); }
catch
{ }
Console.WriteLine(f
== null ? "null"
: "not null");
}
}
Quasi da non credere (J. Duffy, "Professional .NET Framework 2.0", p. 61):
"The actual IL emmited shows some of the complexities of delegates in the underlying type system:"
struct MyDelegate : System.MulticastDelegate{ //[...]}
"[...]
Notice first that the MyDelegate type breaks one of the rules discussed above, namely that structs cannot derive from types other than ValueType. Delegates have special support in the CTS, so this is allowed."
Abbastanza sconvolgente questo paragrafo, non trovate?