2011-09-05 64 views
0

嗯,這是我遇到的錯誤代碼:如何在C#中修復這些錯誤?

this.terminchar = Convert.ToChar(8080);  
List<string> source = new List<string>(this.base64Decode(parse_value).Split(new char[] { this.terminchar })); 

if ((source) % 2) == 0) 
{ 
    for (int i = 0; i < source; i++) 
    { 
    this.keys.Add(source[i], source[++i]); 
    } 
} 

我得到的3個錯誤與此代碼,第一個:

錯誤1操作「<」不能應用於操作數類型 'INT' 和 'System.Collections.Generic.List'

二之一:

錯誤2操作 '%' 不能被應用於類型 'System.Collections.Generic.List' 和 'INT'

第三個的操作數:

錯誤3無效表達術語「= =」

我是相當新的C#,這是我現在只是隨便看看來理解語法我​​的朋友們的源代碼,但我不知道該怎麼辦。任何幫助將不勝感激,謝謝。

回答

3

您正在列表中執行一些操作。我敢肯定,你應該將線如下...

if ((source.Count) % 2) == 0) 

for (int i = 0; i < source.Count; i++) 

代替

+0

像魅力一樣工作,非常感謝:) – Neel

6

您可能會在兩種情況下都尋找.Count屬性。因此使用source.Count

0

您需要使用源的.Count中獲得的項目數在列表

List<string> source = new List<string>(this.base64Decode(parse_value).Split(new char[] { Convert.ToChar(8080) })); 
string Command = source[0]; 
source.RemoveAt(0); 
if ((source.Count) % 2) == 0) 
{ 
    for (int i = 0; i < source.Count; i++) 
    { 
     this.keys.Add(source[i], source[++i]); 
    } 
} 
+2

'List'在C#中沒有'.size()'# – WaltiD

+0

對不起,與Java混淆:)正在編輯 –

1

明顯,可以使用在那裏循環。使用i<source.Count而且(source.Count) % 2而不是

+0

什麼是'source.Length'?編譯器會告訴你。 – leppie

+0

對不起,它會包含計數,因爲它是列表<> –

+0

這是計數不算。 – Ray

0

sourceList<string> - 字符串的容器,見MSDN

運算符<%可以應用於int。所以你的代碼缺少一些東西。