I am making an text-based adventure game
for my first little project in C#. In order for my vision to work I need a few arrays that can be accessed in any of the functions. The game will only consist of a single class. And the arrays will need to be able to be changed in any function.
This question is related to
c#
Your class shoud look something like this:
class Something { int[] array; //global array, replace type of course void function1() { array = new int[10]; //let say you declare it here that will be 10 integers in size } void function2() { array[0] = 12; //assing value at index 0 to 12. } }
That way you array will be accessible in both functions. However, you must be careful with global stuff, as you can quickly overwrite something.
Source: Stackoverflow.com