0

I have a dictionary:

public ConcurrentDictionary<string, List<IronportServerStatus>> IronportServerStatusDict = new ConcurrentDictionary<string, List<IronportServerStatus>>();

In the key there are a lot of hosts (string). Lets take for an example this host abc.def.ghi. In the value there is a list of IronportServerStatus.

The next chase is that I want to remove the the first element of the value [0]. If count >= 10. After that I want to add the new status which I get all 5 minutes. So the maximum count is 10.

I'm getting a List<List<IronportServerStatus>> and removing the first item. After that I'm adding my new logdata which is a IronportServerStatus, this doesn't work also.

var result = SystemCore.Instance.IronportServerStatusDict.Where(o => o.Key == host.Host).Select(o => o.Value).ToList();

if (result.Count >= 10)
{
    result.RemoveAt(0);
}

result.Add(logData);

Can someone help me please?


ANSWER :

SystemCore.Instance.IronportServerStatusDict.Where(o => o.Key == host.Host).FirstOrDefault().Value.RemoveAt(0);
SystemCore.Instance.IronportServerStatusDict.Where(o => o.Key == host.Host).FirstOrDefault().Value.Add(logData);
4

1 回答 1

0

尝试以下

// Get the list
var result = SystemCore.Instance.IronportServerStatusDict[host.Host];

if (result.Count >= 10)
{
    result.RemoveAt(0);
}

result.Add(logData);

Console.WriteLine(SystemCore.Instance.IronportServerStatusDict[host.Host][0]);
于 2013-11-14T10:36:27.857 回答