为什么我不能对 windows 形式 AP 中的 2 个字符串使用相等函数?它总是 return 错误

Why i can't use equal function for 2 string in windows form AP? it's always return False

我用 c# 写了一个简单的 windows_form 应用程序,所以我放了一些用于一些数据的 TextBox 和一个 DataGridView 以及一个按钮,当用户按下按键时,我在 TextBoxes 中的信息将复制到 DataGridView。当我在上面写了一个用于搜索的字符串并单击 Just4Test 按钮时,我的表单有一个用于搜索的文本框 returns 始终为 False value.can 谁能解释为什么?

当你这样做时:

dataGridView1[1, 0].ToString()

你得到了什么?你试过调试吗?根据 documentation DataGridViewCell.ToString() Method:

Unless otherwise noted, the ToString method for all the various cell types will return a string of the form shown in the following code example:

Classname {RowIndex = #, ColumnIndex = #}

我想你想要 dataGridView1[1, 0].Value 的东西。

可能类似于:

searchTextBox.Text == (string)dataGridView1[1, 0].Value

谁知道两者之间有什么不同 testi = searchTextBox.Text ==dataGridView1[1, 0].ToString(); 和 testi = searchTextBox.Text == (string)dataGridView1[1, 0].Value; ??