Question New() Constructor or "=" ?

spdracer22

Member
Joined
Oct 18, 2007
Messages
7
Programming Experience
3-5
Which has a faster execution: assigning values to a structure using a New() constructor, or assigning those values directly?

Example:

Dim temp as myStructure = New myStructure(1,2,3)

or

Dim temp as myStructure
temp.a = 1
temp.b = 2
temp.c = 3

Assume the New() constructor contains the same code as assigning each value directly, only I wouldn't have to use those three 'extra' lines of code every time I wanted to use that structure type.
 
The latter is faster, but using a constructor has obvious coding and design benefits, so using that method is 'better'. Try Stopwatch class.
 
Don't worry about it then

Yeah, I actually did it the "=" way at first, but once I realized I could use constructors inside structures, the coding benefits (like JohnH suggested) of using the constructor were pretty big. I just wanted to make sure there wasn't some big memory or speed issue I was missing by doing things one way or another.

Thanks for the help, guys.
 
Back
Top