开发者

How can I fix these errors in C#?

Well this is the code I'm having errors with:

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]);
  }
}

I get 3 errors with this code, fir开发者_Python百科st one:

Error 1 Operator '<' cannot be applied to operands of type 'int' and 'System.Collections.Generic.List'

Second one:

Error 2 Operator '%' cannot be applied to operands of type 'System.Collections.Generic.List' and 'int'

Third one:

Error 3 Invalid expression term '=='

I'm fairly new to C# and this is my friends source code which I'm just looking at to understand the syntax but I have no idea what to do. Any help given would be appreciated, thanks.


You probably looking for the .Count property in both cases.

So use source.Count.


You are doing some operations on a list. I'm quite sure, you should your lines as follows...

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

and

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

instead


obviously, you can use there in for loop. use i<source.Count and also (source.Count) % 2 instead


source is List<string> - a container for strings, see MSDN.

Operators < and % can be applied to int. So your code is missing something.


You need to use the .Count on source to get the count of items in the List

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]);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜