0

I'd like to read every 2nd variable from result[] to questions.

string[] questionstr = null;
int ii = 0;
for (int i = 0; result.Length > i;)
{
  questionstr[ii] = result[i];
  ii = ii+1;
  i = i+2;
}

it gives me System.NullReferenceException at ii=ii+1; I tried ii++; too but same error.

Greg Zetko
  • 93
  • 2
  • 8

2 Answers2

1

Your NullReferenceException must be from the line above:

questionstr[ii] = result[i];

Your array questionStr isn't initialized. Trying to use it is causing the exception.

You should initialize it before using it, like this:

string[] questionStr = new string[result.Length];

so that the array size is large enough to hold all your results

pb2q
  • 54,061
  • 17
  • 135
  • 139
0

You have to initialize the string array questionstr as following:

 var questionStr = new string[result.Length/2+1];