-1

I have following lines of code, According to Command List Item, it should goes into if block, but it is not going there. In debug mode int[] ckeys shows just {int[0]} not any value, can you tell me what is the problem?

List<string> Command=new List<string>();
string ASCLICAL = "Callers:";
string ASCLIMEM= "Members:";
string ASCLINOCAL="NoCallers";

int[] ckeys = Command.Select((s, idx) => new { Str = s, Idx = idx })
                    .Where(p => p.Str == ASCLICAL)
                    .Select(p => p.Idx)
                    .ToArray();

if(ckeys == null) {
                    ckeys = Command.Select((s, idx) => new { Str = s, Idx = idx })
                            .Where(p => p.Str == ASCLINOCAL)
                            .Select(p => p.Idx)
                            .ToArray();
            }

Command List Contains:

[0] = "300 has 0 calls (max unlimited) in 'ringall' strategy (173s holdtime), W:0, C:1, A:0, SL:0.0% within 0s"
[1] = "Members:"
[2] = "Local/409@from-internal/n (In use) has taken 1 calls (last was 64167 secs ago)"
[3] = "No Callers"
[4] = ""
4

2 回答 2

1

它永远不会为空。如果数组不包含元素,那么它将始终是一个包含 0 个元素的数组。

您可以使用Array.LengthorArray.Count并检查大小是否 > 0

   if (ckeys.Length == 0) {

   }
于 2013-06-07T09:46:04.250 回答
1

ckeys不为空,它是空的。你应该ckeys == null改为ckeys.Length == 0

于 2013-06-07T09:46:44.307 回答