Passing Variables By Value or Reference

Summary

To summarize this simple tutorial, I would like to suggest the following few things to think of.

  1. ByRef is faster to call, and it is the default for a good reason.
  2. Use ByRef if the value is very long. Why use a copy of a very long string, when all you need to do is use the memory address location?
  3. When using multiple options, order them ByRef, ByVal, Optional.
  4. Evaluate if a Constant will be constant at all times or if you can save your self re-coding hassles by using default Optional arguments.
  5. Come to think of it, did I just manage to make constants less constant or what?

An a final note to something I have often found out the hard way in all of my coding and after pounding out perfect code that never works as fast anywhere else as on my own computer.

Test, try, twist and turn, because no matter how much you learn form reading, the final speed check really comes around when you try the code and add a few timers to test it in practical forms.

As I have also learned, it is not always needed to have high speed on all you do, but if your function is for example used in recursive loops then more than ever should you look at details.

The number of repetitions will slow down the speed of your application enormously if you choose the wrong way to do things.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match” - Bill Bryson