2011-09-05 65 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。所以你的代码缺少一些东西。