Q:

Get "Object reference not set to an instance of an object." even if I exclude null

I have the following code using the datagridview which you can only select one whole row:
"Variable.addModArray[i]" is a string[];
class Variables
{
    public static string[] addModArray;
}

int i = 0;
while (i < dgv.SelectedRows.Count)
{
    if (dgv.SelectedRows[0].Cells[i].Value != null)
        Variables.addModArray[i] = dgv.SelectedRows[0].Cells[i].Value.ToString(); //gets error
    i++;
}

When I run the code, I get the "Object reference not set to an instance of an object." error, but I already told the computer do the code if the value is not null! Did I do anything wrong?
Tell me if I need to add anything to this question.

A:

It could also be that Variables or addModArray are null.

