0

I am simply trying to write months to an array in a certain order.

                                string January = "January";
                                string February = "February";
                                string March = "March";
                                string April = "April";
                                string May = "May";
                                string June = "June";
                                string July = "July";
                                string August = "August";
                                string September = "September";
                                string October = "October";
                                string November = "November";
                                string December = "December";

and then writing to the array like so:

                            for (int i = 0; i < (janC - 1); i++)
                                {
                                    analyser.sortedmonths[i] = January;
                                }

sortedmonths is initialized in another cs sheet. The sorted months array is 1022 in size as that is the amount of months being read in.

Why is this not working? I have googled the null reference exception but have not found anything related to writing to an array.

Durell
  • 11
  • 6

1 Answers1

0

analyzer.sortedmonths is null. You have to initialize it:

analyzer.sortedmonths = new string[12];
zmbq
  • 38,013
  • 14
  • 101
  • 171
  • I have 1022 months being read in, i am counting how many there are of each months, then rebuilding the array in calendar order. I have initialized this string array. – Durell Apr 19 '16 at 21:34