I declared the following array variable as public and in my frmMain_Load it seemed to populate the array alright, but in my button1_Click, it said the arrayofDots[] is null. Does anyone have any ideas? Thanks in advance.
public partial class frmMain : Form
{
public string[] arrayofDots;
-----
private void frmMain_Load(object sender, EventArgs e)
{
string[] arrayofDots = new String[20];
for (int cc = 0; cc <= 15; cc++) { arrayofDots[cc] = new string('.', 17 - cc); }
}
-----
private void button1_Click(object sender, EventArgs e)
{
for (int ii = 0; ii <= 15; ii++)
{
if (st.StartsWith(arrayofDots[ii].ToString()))
Loading
VulpesPosted Jan 17, 2014, 4:25 PM
string[] arrayofDots = new String[20];
If you change it to this, then all should be well:
arrayofDots = new String[20];
What you've done is to create another array called arrayOfDots which is local to the Load eventhandler and then initialized that. The class level array, also called arrayOfDots, is still null - hence the error.