-4

那个 string.compiler 东西有一个错误,我不知道该怎么做。我真的需要一些帮助

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] == '\0')
    {
        char[] temp = new char[100];
        for (int j = 0; j < i - beg; j++)
        {
            temp[j] = valWord[beg + j];
        }
        temp[i - beg] = '\0';


//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] == '\0')
        {
            value += val;
            break;
        }
    }
    Console.WriteLine(textBox2.Text);

}
else
{
    _list.Add(name, new GenericList());
}
4

2 回答 2

2

You can't compare a string to a char array. They are different types.

Use if (string.Equals(new string(temp),"thousand")) instead.

于 2012-09-23T03:02:07.977 回答
0

根据MSDN,没有为 String.Compare 定义这样的函数重载

于 2012-09-23T03:16:57.043 回答