I have a datagridview in a C# winforms app, and I’m comparing the values in a certain cell in each row to an item in an array that I read into from a file.
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();
}
}
So, for each row dr in the datagridview, I look at the cell at AcctNoIndex-1. If that value equals the value in this array I read some data into, items[custAcctNo-], I do the following stuff.
I was debugging the code, however, and I noticed in the Watch window, that items[custAcctNo-1] was the same as dr.Cells[AcctNoIndex-]. For one of the rows, the values are the same. However, when I step through the debugger, the program skips everything in the if block and just continues.

Can anyone help me with this? I think that since both values are strings, the condition should be true, and the program should continue in the if block, but I’m confused as to why the debugger thinks the two values are not the same.
One says string, one is an object. Cast them both to strings and it will work.