2009-10-16

Reference types

Quick reminder: Any object you have to instantiate (e.g. create with the new keyword) is what’s called a Reference Type. It means that, when used as a method parameter, it will always be treated as a reference parameter (ref in C#, ByRef in VB).

In other words, this is redundant:

  1: void ModifyData(ref DataSet data)
  2: {
  3:     //....
  4: }

Because DataSet is a reference type, the ref keyword in the above examples serves no use. 

Opposite to reference types are Value Types, like an int or a string. They have to specify the ref keyword in the parameter if they want to be treated as such.

Here’s a good article on reference and value types.

See ya.

No hay comentarios:

Publicar un comentario

Your tips and thoughts are always welcome, and they provide good motivation: