2012-09-23 45 views
-4

該string.compiler thingy有一個錯誤,我不知道該怎麼做。我真的需要一些幫助如何使用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] == '\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()); 
} 
+0

什麼是錯誤?你有什麼跡象表明存在問題? – David

回答

2

你不能比較一個字符串到一個字符數組。他們是不同的類型。

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

+0

非常感謝!你是天使! :DD – BossJhen

0

根據MSDN,沒有爲String定義這樣的函數重載。比較

相關問題