Variable references

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

Hi all,

I think this is probably a simple one for any c# expert -

I would like to declare a variable say

int SomeIntVariable;

and also an array:

int[] SomeIntArray;

Now I would like to be able to assign an element of the array to the
variable - that is so that the array element and the variable occupy the
same address space. The idea is that when the variable is modified the array
element reflects the change and vice versa.

Thanks -

Joe
 
Joe,

You can not do this. You do not have access to the addresses of
variables in memory. If you want to do something like this, wrap your
values in a class wrapper, then assign the class wrapper to your array.
Then, when you change the value in the array, the value in your instance
changes as well.

Hope this helps.
 
Many thanks - I'll give it a try.

Nicholas Paldino said:
Joe,

You can not do this. You do not have access to the addresses of
variables in memory. If you want to do something like this, wrap your
values in a class wrapper, then assign the class wrapper to your array.
Then, when you change the value in the array, the value in your instance
changes as well.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Joe said:
Hi all,

I think this is probably a simple one for any c# expert -

I would like to declare a variable say

int SomeIntVariable;

and also an array:

int[] SomeIntArray;

Now I would like to be able to assign an element of the array to the
variable - that is so that the array element and the variable occupy the
same address space. The idea is that when the variable is modified the
array element reflects the change and vice versa.

Thanks -

Joe
 
Back
Top