Inline parameter declaration eg: ...New Size(10,10))

  • Thread starter Thread starter Nigel V Thomas
  • Start date Start date
N

Nigel V Thomas

Hi

I've always use the following code.

Dim Sz as new Size

Sz.Width=10
Sz.Height=10

call SomeRoutine (Sz)

However, I see you can use:

call SomeRoutine (new Sz(10,10))

which seems a real shortcut.

Is it safe? Overheads? bad style?

Comments pls

Nigel
 
Hi

I've always use the following code.

Dim Sz as new Size

Sz.Width=10
Sz.Height=10

call SomeRoutine (Sz)

However, I see you can use:

call SomeRoutine (new Sz(10,10))

which seems a real shortcut.

Is it safe? Overheads? bad style?

Safe? Sure. As long as you don't care about any what Sz may contain after
the call to SomeRoutine (assuming SomeRoutine may modify the values).

Overheads? I can't see how it would generate any additional overhead.
All the compiler is probably going to do is declare a temporary value of
type Sz and then pass that to SomeRoutine. Though, I haven't verified that in
the IL - it seems the logical approach.

Bad style? LOL... Well you will always find someone that thinks anything is
bad style :) But, personally, I do this all the time. Seriously, if you
don't care about the values contained in your type Sz beyond the call to
SomeRoutine - why bother declaring the extra variable?
 
Tom

Thanks for the re assurance on that.

Just a point, if I receive the sz structure as BYREF then does this mean any
changes would not be passed back to the calling routine?

Nigel
 
Tom

Thanks for the re assurance on that.

Just a point, if I receive the sz structure as BYREF then does this mean any
changes would not be passed back to the calling routine?

Technically, the changes would be passed back - but, the caller would have no
way of knowing you made the change or making use of them. Of course, all you
can do is assume the caller didn't care about those values anyway - and to be
honest, that can be the case at times :)
 
Back
Top