Tuesday, May 03, 2005

Reference/Value type/parameter

I had to look up how parameters are passed to functions (in C#). Found an excellent article explaining the difference between value and reference types, on the one hand, and pass-by-value and pass-by-reference, on the other: Jon. For me, it was easiest to remember the different scenarios by thinking of pointers and pointers to pointers, e.g., a reference type is like pointer and a reference type passed-by-reference is like a pointer to a pointer. Now I just have to remember which types are value types and which are reference types :) An additional good point made by Jon is that a string, although being a reference type, is immutable, so it can be passed around without fear of it changing unexpectedly.

No comments: