Re: Convert String to variable contained in string

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Gregory,

In order to do something like this, you would have to create a wrapper
for the value which is a reference type, and then pass that around, instead
of the int itself. This way, if you change the wrapper, you are changing
instances, and when the wrapper is assingned to the variable, they all point
to the same wrapped integer.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx

"gmccallum" <gmccallum@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:89E2D8DD-8233-4E3F-8B2E-A02246A4D922@xxxxxxxxxxxxxxxx
> The reason I am doing this approach to a problem is because I
> don't know how to create a reference to a value type.
>
> For example in C++:
> int x = 10;
> int *y = &x;
>
> When I update x, I want to be able to see the change in y.
>
> In C# because int is a value type when I say:
> int x = 10;
> int y = x;
> it creates a copy of x and puts it in y.
>
> Is there a way to do this without having to use unsafe construct?
>
> It still would be useful to be able to get the value of a variable in a
> string like
>
> string varName = "MyClass.intvalue";
> would like to get value of MyClass.intvalue.
>
> So an answer to both issues would be really appreciated.
>
> -Gregory McCallum
>


.



Relevant Pages