I have an array being returned but as I’m new to programming I can’t work out how to read each value. Can someone please point me in the right direction?
My code is below.
private void testToolStripMenuItem_Click(object sender, EventArgs e) { foreach (int name in getNames()) //<----I'm wrong here I guess { MessageBox.Show(name.ToString()); } } private ArrayList getNames() { //some code... .. ... return names; }
Thanks all
Firstly, you’re not returning an array, but rather an
ArrayListinstance. Secondly, why would a name be anint? Surely you meanstring? Finally, if you’re on .NET 2.0 or later, you can use generics to improve your code. So, useList<string>rather thanArrayList.