I'm having an issue using an array declared in the "Form1_Load". My Goal is to be able to assign values to the array and then subtract from certain values within it.
The array is an array of structs. I am thinking that I have to publicly declare the array elsewhere. Right now I wanna try to do the majority of this within the "Form1_load".
What I am trying to achieve would be if a user clicks a picture, it should update how many items are left(starting at 20) and add the total to a label. There is 5 different pictures they can click to do so, which is where the array comes in need.
the structure:
struct Drink
{
public string name;
public int cost;
public int numberOfDrinks = 20;
}
- The structure is within the namespace, above the partial class. *
load event:
private void Form1_Load(object sender, EventArgs e)
{
const int SIZE = 5;
Drink[] drink = new Drink[SIZE];
}
- This is where I want to have the array*
here is an example of what should happen if a picture is clicked:
private void picCola_Click(object sender, EventArgs e)
{
drink[0].cost = 1.5;
drink[0].name = "";
}
- However, the message "The name 'drink' does not exist in the current context" appears. Does the array need to be public?