(Inline)
Herfried K. Wagner said:
'New' is optional for value types, except when calling a value type's
parameterized constructor. So, 'New' is /not/ an indicator for a type being
a value type!
Where did I say it was an indicator? I simply said it wasn't used for value
types. You seem to say I said New was not allowed, but read it again, I
simply said it was not used. Perhaps that would have been better said, 'New
is not commonly used ...' but I didn't think I would need to elaborate!
Where the value is stored and/or if the variable is placed on another
position is an implementation detail which it's not worth to worry about,
What does that mean? Are you trying to say that the machine code does not
indicate how variables are treated? If that is it, I'd have to differ, if it doesn't
happen at the machine code level, then it doesn't get done....
What I showed indicated that there was no code executed that either destroyed
or created a reference, as was indicated by Scott's statement:
What I posted indicated that X=Nothing was identical to X=0, and thus, no
destruction took place.
Investigating further shows that using New on a value type does have an
adverse effect (MSIL and Assmbly):
//000046: Dim a As Integer
//000047: a = Nothing
IL_0001: ldc.i4.0
IL_0002: stloc.0
//000048: a = 0
IL_0003: ldc.i4.0
IL_0004: stloc.0
//000049:
//000050: Dim b As New Integer
IL_0005: ldloca.s b
IL_0007: initobj [mscorlib]System.Int32
//000051: b = Nothing
IL_000d: ldc.i4.0
IL_000e: stloc.1
//000052: b = 0
IL_000f: ldc.i4.0
IL_0010: stloc.1
00000007 xor eax,eax
00000009 mov dword ptr [ebp-10h],eax
0000000c mov dword ptr [ebp-4],ecx
0000000f mov dword ptr [ebp-8],edx
00000012 xor esi,esi
00000014 nop
a = Nothing
00000015 xor esi,esi
a = 0
00000017 xor esi,esi
Dim b As New Integer
00000019 mov dword ptr [ebp-10h],0
b = Nothing
00000020 mov dword ptr [ebp-10h],0
b = 0
00000027 mov dword ptr [ebp-10h],0
Even while using New adds a level of indirection, it still shows that
setting a value type to Nothing is 'exactly the same' as assigning a
value of 0. No one would try to claim that assigning a value of 0
causes the variable to be destroyed, would they?
LFS