Not to step on your toes obislavu, but C# doesn't work that way. It is much more like Java than C++ in terms of passing variables to functions.
In C# their are two types of types, object (reference, etc) types (string, DataTable, etc) and value types (int, float, any struct, etc). When an object type is passed to a function, the default is by reference, since all that you have is a reference anyway. This means any changes you make to the object remain after the function completes. [Be careful about tesing this with strings as they are immutable, meaning string functions don't change strings, they just make new ones.]
Value types are different, as they are copied when passed to function. In order to pass a value type by reference (without using unsafe pointers), you must use the ref modifier in the function prototype. This allows the function to make permanent modifications to the variable.
One final note, passing an object type with the ref modifier means that the actual variable itself can be changed, not just the object. The following example demonstrates:
Code:
StringBuilder temp = new StringBuilder("Hello World!");
foo(temp);
...
void foo (StringBuilder s) {
s = new StringBuilder("Goodbye World!");
}
after foo, temp is still "Hello World!", becuase only the object can be modified. However:
Code:
StringBuilder temp = new StringBuilder("Hello World!");
foo(ref temp);
...
void foo (ref StringBuilder s) {
s = new StringBuilder("Goodbye World!");
}
now after foo, temp is "Goodbye World!".
If you have any more questions, let me know.
"Programming is like sex, one mistake and you have to support it forever."
John
johnmc@mvmills.com