運算符'!='不能應用於類型'string []'和'字符串'的操作數 (是的,我知道類似的問題之前曾被問過,正在使用的上下文/元素是不同的類型,所以我會很感激幫助我的情況:))不等式運算符不適用於字符串數組
我有一個文件,我想停止閱讀,只要我擊中以「0」開頭的行文件。 我的while循環與不等式運算符有關。
private void button1_Click(object sender, EventArgs e)
{
// Reading/Inputing column values
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string[] lines = File.ReadAllLines(ofd.FileName).Skip(8).ToArray();
textBox1.Lines = lines;
while (lines != "0") // PROBLEM Happens Here
{
int[] pos = new int[3] { 0, 6, 18 }; //setlen&pos to read specific colmn vals
int[] len = new int[3] { 6, 12, 28 }; // only doing 3 columns right now
foreach (string line in textBox1.Lines)
{
for (int j = 0; j < 3; j++) // 3 columns
{
val[j] = line.Substring(pos[j], len[j]).Trim(); // each column value in row add to array
list.Add(val[j]); // column values stored in list
}
}
}
}
與 的foreach替換,而(行= 「0」!) – CSharpie