Link to home
Start Free TrialLog in
Avatar of pcad696
pcad696

asked on

Pointers (references to value types?) in VB.NET

I have a class that has maybe 50 different parameters to save, load, print and initalize to default values (think of an INI file for example).
I would like to have a central ParmArrayList (say) where the name, default value, allowable range for each parameter is stored (easy so far).

I would also like this ParmArrayList to contain a pointer (or reference) to the variable that contains the actual parameter so that I may easily read/write/print all parameters by iterating through the ParmArrayList.  This will be easy with string parameters (because I can easily store a reference to a string object), but for value types such as Integer or Boolean, it does not work.

Is there any way at all to somehow store the address of an integer or boolean value (to later read or write such variables through one level of indirection)

Or any ideas how I can achieve my general idea of iterating an array rather than having 50 lines of code to initialize my parameters, another 50 lines to read them, another 50 lines to write them, you get the drift...

P.S. I understand what ByRef is (and that is just fine when you want to use the ref immediately within a method; my problem is can I store the ref (to a value type)for later use
 
Avatar of pcad696
pcad696

ASKER

one more thing, I don't have control over all the variables that store the parameters, so wrapping all integers and booleans in a dummy class is not really an option
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Haha...didn't refresh the page...
Avatar of pcad696

ASKER

Your comment is interesting (I will look into it, and it will probably be worth some points :) , but as I said in my follow-on comment, I don't control all the variables, they are in three separate classes, and I would prefer not having to make yet another wrapper.

Is there any way in VB.NET to store a pointer (or reference) to a variable of value type?
There may be...but VB.Net was specifically designed to NOT do this...so I don't know how to do it offhand...

It is possible to get the values of variables by name via Reflection but then you would be going down the same road as 50 different lines to grab each one...
Avatar of pcad696

ASKER

I am curious, why do you say VB is designed NOT to do this, it does after all provide the equivalent of pointers for reference types; so yes, value types are explicitly different, but are you saying that they wanted to avoid pointers to value types because they are dangerous in some sense?