如何使用 String.compare



那个字符串有错误,我不知道该怎么办。 我真的需要一些帮助。

char[] valWord = new char[100];
Console.WriteLine(textBox1.Text);
valWord = textBox1.Text;
int beg = 0;
int val = 0;
int value = 0;
for (int i = 0; i < 100; i++)
{
    if (valWord[i] == ' ' || valWord[i] == '')
    {
        char[] temp = new char[100];
        for (int j = 0; j < i - beg; j++)
        {
            temp[j] = valWord[beg + j];
        }
        temp[i - beg] = '';

//there is an error in this if statement: String.Compare
        if (String.Compare(temp, "thousand") == 0)
        {
            value += (val*1000);
            val = 0;
        }
        else if (String.Compare(temp, "hundred") == 0)
        {
            value += (val*100);
            val = 0;
        }
        else if (String.Compare(temp, "one") == 0)
        {
            val = 1;
        }
        else if (String.Compare(temp, "two") == 0)
        {
            val = 2;
        }
        if (valWord[i] == '')
        {
            value += val;
            break;
        }
    }
    Console.WriteLine(textBox2.Text);
}
else
{
    _list.Add(name, new GenericList());
}

不能将字符串与字符数组进行比较。 它们是不同的类型。

请改用if (string.Equals(new string(temp),"thousand"))

根据 MSDN,没有为 String.Compare 定义此类函数重载。