assigning classes to an array of structs c# -
i'm having issue using array declared in "form1_load". goal able assign values array , subtract values within it.
the array array of structs. thinking have publicly declare array elsewhere. right wanna try majority of within "form1_load".
what trying achieve if user clicks picture, should update how many items left(starting @ 20) , add total label. there 5 different pictures can click so, array comes in need.
the structure:
struct drink { public string name; public int cost; public int numberofdrinks = 20; } - the structure within namespace, above partial class. *
load event:
private void form1_load(object sender, eventargs e) { const int size = 5; drink[] drink = new drink[size]; } - this want have array*
here example of should happen if picture clicked:
private void piccola_click(object sender, eventargs e) { drink[0].cost = 1.5; drink[0].name = ""; } - however, message "the name 'drink' not exist in current context" appears. array need public?
when declare array drink inside function form1_load becomes local function only. no 1 else can see it. need change scope of variable become global (it doesn't need public).
private drink[] drink; private void form1_load(object sender, eventargs e) { const int size = 5; drink = new drink[size]; } you can, however, instantiate elsewhere.
Comments
Post a Comment