c# - Why am I getting an error indicating that my variable doesn't exist, when I've already defined it? -
i error indicating myrandomarray
doesn't exist in current context. how access variables across classes in c# winforms application?
public void quiz_load(object sender, eventargs e) { string[] myrandomarray = getwordlist(); } private void timer1_tick(object sender, eventargs e) { somefunction(myrandomarray);/// myrandomarray doesn't exist in current context. }
you've defined array, only in scope of quiz_load
method, scope of timer1_tick
has no knowledge of it. if declare instance member of class, accessible instance method:
private string[] myrandomarray; public void quiz_load(object sender, eventargs e) { this.myrandomarray = getwordlist(); } private void timer1_tick(object sender, eventargs e) { somefunction(this.myrandomarray); // no problem }
further reading
Comments
Post a Comment