Is New needed? Dim lPF2 = New PARAFORMAT2

  • Thread starter Thread starter Just Me
  • Start date Start date
J

Just Me

The below seems to work. But I just saw similar code the did:
Dim lPF2 = New PARAFORMAT2
Now I'm wondering, do I need the New?
If not, why not?

Thanks



Dim lPF2 As PARAFORMAT2
lPF2.dwMask = RichEdit.PFM_SPACEBEFORE Or RichEdit.PFM_SPACEAFTER
lPF2.cbSize = Marshal.SizeOf(lPF2)
lPF2.dySpaceAfter = 1440 * lSpaceAfter
lPF2.dySpaceBefore = 1440 * lSpaceBefore
SendMsg(hwnd, EM_SETPARAFORMAT, 0, lPF2)
 
Just Me said:
The below seems to work. But I just saw similar code the did:
Dim lPF2 = New PARAFORMAT2
Now I'm wondering, do I need the New?

'PARAFORMAT2' is a structure and structures value types. You only need
'New' if you are calling a non-parameterless constructor of the structure.
 
'PARAFORMAT2' is a structure and structures value types. You only need
'New' if you are calling a non-parameterless constructor of the structure.

I think I read, that New should be called even for
Structures. As a matter of good practice.
Roger
 
thanks
Herfried K. Wagner said:
'PARAFORMAT2' is a structure and structures value types. You only need
'New' if you are calling a non-parameterless constructor of the structure.
 
Roger said:
I think I read, that New should be called even for
Structures. As a matter of good practice.


Sematically there is no difference in whether you use 'New' in this
situation or not. Do you really always type 'Dim i As New Integer'?!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top