我希望能够将值从 Form1 中的一个 DataGridView 传输到 Form3 中的另一个 DataGridView。为此,我选择在 3 个不同的变量中过滤它们,这些变量将在类中,以便稍后在 Form3 中访问它们。
这些是类:(我已经将它们作为一个具有 3 个变量的类)
public class verify1
{
    public static int[] CodUser { get; set; }
}
public class verify2
{
    public static DateTime[] DataFim{ get; set; }
}
public class verify3
{
    public static string[] Nome { get; set; }
}
尽管如此,当我为变量赋值时,我在第一次运行 for 时得到了 NullReferenceException。
这是我用来赋值的代码:
int a = 0;
for (int i = 0; i < dataGridView1.RowCount - 1; i++)
{    
    DateTime date = Convert.ToDateTime(dataGridView1.Rows[i].Cells[2].Value);   
    if (date <= DateTime.Now)   
    {   
        verify1.CodUser[a] = Convert.ToInt32(dataGridView1.Rows[i].Cells[0].FormattedValue);    
        verify2.DataFim[a] = Convert.ToDateTime(dataGridView1.Rows[i].Cells[2].FormattedValue);
        verify3.Nome[a] = Convert.ToString(dataGridView1.Rows[i].Cells[3].Value);   
        a++;   
    }
}
现在,我不明白为什么 Visual Studio 说该值为空。异常发生在以下行:
verify1.CodUser[a] =   Convert.ToInt32(dataGridView1.Rows[i].Cells[0].FormattedValue);
(即17389)首先,不会让我走得更远。我不明白为什么它返回null。顺便说一句,DataGridView 完全由数据实现。
为什么它返回null?