have alook on the ildasm code :
The first assignment
DelegateType methodPointer = new DelegateType(SomeMethod);
==========================================
..method public hidebysig instance void A() cil managed
{
// Code size 15 (0xf)
.maxstack 3
.locals init ([0] class CheckDelegate.Class1/DelegateType methodPointer)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldftn instance void CheckDelegate.Class1::SomeMethod()
IL_0008: newobj instance void
CheckDelegate.Class1/DelegateType::.ctor(object,
native int)
IL_000d: stloc.0
IL_000e: ret
} // end of method Class1::A
The Second assignment :
..method public hidebysig instance void B() cil managed
{
// Code size 15 (0xf)
.maxstack 3
.locals init ([0] class CheckDelegate.Class1/DelegateType methodPointer)
IL_0000: nop
IL_0001: ldarg.0
IL_0002: ldftn instance void CheckDelegate.Class1::SomeMethod()
IL_0008: newobj instance void
CheckDelegate.Class1/DelegateType::.ctor(object,
native int)
IL_000d: stloc.0
IL_000e: ret
} // end of method Class1::B
As you can see the compiler do the same for both statements.
Conclusion :
They both are the same.
--
Sincerely
Yaron Karni
http://dotnetbible.blogspot.com/
"Carl Johansson" wrote:
Suppose I have a delegate variable, what is the difference between the
following two statements?
DelegateType methodPointer = new DelegateType(SomeMethod);
and...
DelegateType methodPointer = SomeMethod;
Both statements compile, and when the program runs I can't see any
difference in behavior? Is the constructor somehow automatically called in
the second case?
Regards Carl Johansson