1

I have a web service that I am calling which take a string, and returns a list of strings as an object[].

I want to covert this to a Dictionary> object. I'm currently using something like this:

foreach (string role in allRoles)
{
    Dictionary<string, List<string>> allActionsForRole = 
        lifeRay.getRoleActions(role)
        .ToDictionary<string, List<string>>(role, x => x.ToString());
}

It doesn't like the "role" field.

How should I write this?

I'm assuming I could write it somehow to even remove the foreach, right?

4

1 回答 1

2

尝试以下操作:

Dictionary<string, List<string>> allActionsForRole = 
    lifeRay.getRoleActions(role)
    .ToDictionary<string, List<string>>(() => role, x => x.ToString());

该方法需要两个Func代表 - 因此您可以为密钥提供一个“虚拟”代表。

于 2012-09-18T20:12:24.503 回答