这是我遇到错误的代码:
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运算符'&lt;'不能应用于'int'和'System.Collections.Generic.List'
类型的操作数
第二个:
错误2运算符'%'无法应用于'System.Collections.Generic.List'和'int'类型的操作数
第三个:
错误3无效的表达式术语'=='
我是C#的新手,这是我的朋友源代码,我只是想了解语法,但我不知道该怎么做。任何给予的帮助将不胜感激,谢谢。
答案 0 :(得分:6)
在这两种情况下,您可能都在寻找.Count
属性。
所以请使用source.Count
。
答案 1 :(得分:3)
您正在对列表执行某些操作。我很确定,你应该按照以下方式行......
if ((source.Count) % 2) == 0)
和
for (int i = 0; i < source.Count; i++)
代替
答案 2 :(得分:1)
i<source.Count
和(source.Count) % 2
代替
答案 3 :(得分: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]);
}
}
答案 4 :(得分:0)
source
是List<string>
- 字符串的容器,请参阅MSDN。
运算符<
和%
可以应用于int。所以你的代码遗漏了一些东西。