C# 将datagridview值与数组中的项进行比较

C# 将datagridview值与数组中的项进行比较,c#,winforms,datagridview,C#,Winforms,Datagridview,我在C#winforms应用程序中有一个datagridview,我正在将每行中某个单元格中的值与从文件读取到的数组中的一个项进行比较 foreach (DataGridViewRow dr in dataGridView2.Rows) { if (dr.Cells[AcctNoIndex-1].Value == items[custAcctNo-1])//row in datagridview that contains

我在C#winforms应用程序中有一个datagridview,我正在将每行中某个单元格中的值与从文件读取到的数组中的一个项进行比较

 foreach (DataGridViewRow dr in dataGridView2.Rows)
                {
                    if (dr.Cells[AcctNoIndex-1].Value == items[custAcctNo-1])//row in datagridview that contains the customer account number
                    {
                        items[custState-1] = dr.Cells[ShipStateIndex-1].Value.ToString();
                        items[custCountry-1] = dr.Cells[ShipCountryIndex-1].Value.ToString();
                        items[custShipState-1] = dr.Cells[ShipStateIndex-1].Value.ToString();
                        items[custShipCountry-1] = dr.Cells[ShipCountryIndex-1].Value.ToString();
                    }

                }
因此,对于datagridview中的每一行dr,我查看AcctNoIndex-1处的单元格。如果该值等于我将一些数据读入的数组items[custAcctNo-]中的值,我将执行以下操作

然而,我在调试代码,我注意到在Watch窗口中,items[custactno-1]与dr.Cells[AcctNoIndex-]相同。其中一行的值相同。但是,当我单步执行调试器时,程序会跳过if块中的所有内容并继续执行


有人能帮我吗?我认为,由于这两个值都是字符串,因此条件应该为true,并且程序应该在if块中继续,但我不明白为什么调试器认为这两个值不相同。

一个表示字符串,一个表示对象。将它们都转换为字符串,它就会工作。

一个表示字符串,一个表示对象。把它们都放在弦上,它就会起作用