Storing data in an array that is accessed by separate void c# -
i want design program populates 2d array in 1 void , accesses results another. ie array @ program level not void level.
can advise on syntax? in vba simple, private myarray() variant @ top of module. struggling adapt this.
thanks in advance!
namespace public_collection2 { public partial class form1 : form { public form1() { initializecomponent(); } private void button1_click(object sender, eventargs e) { string[,] info = new string[2, 2]; info[0, 0] = "jn"; info[0, 1] = "565"; info[1, 0] = "gd"; info[1, 1] = "700"; foreach (var item in info) { if (isnotdigits(item)) { combobox1.items.add(item); } } } bool isnotdigits(string str) { foreach (char c in str) { if (c < '0' || c > '9') return true; } return false; } private void combobox1_selectedindexchanged(object sender, eventargs e) { foreach (var item in info)//info not accessible { //pullout relevant number in 2d array } } } }
put
string[,] info = new string[2, 2];
outside method (but inside class). becomes instance field (accessible methods) instead of local variable.
Comments
Post a Comment