C#将值输入到多维数组

时间:2015-07-20 18:54:36

标签: c# arrays multidimensional-array datagridview

我用c#构建一个程序,并在其上包含了dataGridView。我对dataGridView数据进行数学运算,然后将结果插入到多维数组中。但我收到错误消息,说“对象引用未设置为对象的实例”。

这里是我的代码:

  1. frm_clustering.cs

    public void hitungMatriksJarak()
    {
        clusteringModel cm = new clusteringModel();
    
        int i = 0;
        int j = 0;
        for (i = 0; i < this.dgv_clustering.Rows.Count; i++)
        {
            for (j = 0; j < this.dgv_clustering.Rows.Count; j++)
            {
                cm.matriks[j,i] = Math.Sqrt(Math.Pow(Convert.ToDouble(this.dgv_clustering[1, i].Value), 2) +
                                             Math.Pow(Convert.ToDouble(this.dgv_clustering[2, i].Value), 2) +
                                             Math.Pow(Convert.ToDouble(this.dgv_clustering[3, i].Value), 2) +
                                             Math.Pow(Convert.ToDouble(this.dgv_clustering[4, i].Value), 2));
            }
        }
    }
    
  2. clusteringModel.cs:

    class clusteringModel
    {
        private int _jmlKel;
        public int jmlKel
        {
            get { return _jmlKel; }
            set { _jmlKel = value; }
        }
    
        private double[,] _matriks = new double[500,500];
        public double[,] matriks
        {
            get { return _matriks; }
            set { _matriks = value; }
        }
    }
    

0 个答案:

没有答案