Question by
davidovitch82 · Sep 24, 2015 at 02:11 AM ·
arraysreferencing
How can I load a reference to an int into an int array? (c#)
I just want to fill an array of integers with references to the original variables, so that any changes I make are also reflected in the original variables. In the example below I am copying the value of myInt into the array:
int[] myArray;
//this line copies the value of myInt instead of a reference:
myArray[0] = GetComponent<myScript>().myInt;
In order to get a reference instead I am assuming I should use the ref keyword somewhere? I couldn't find any examples of this..
Thanks in advance for any help!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612034840im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why does this loop throw an error if int questComplete rises above 1? 0 Answers
Converting a string name to a sprite 2 Answers
Array problem, I'm novice 1 Answer
Remove empty "" strings from array String[] 1 Answer
Cannot Set Array Size in Inspector 2 Answers