0

これは私のエンティティ コレクションです。

Dictionary<string, List<Dictionary<string, string>>> EntityCollection = new Dictionary<string, List<Dictionary<string, string>>>();

で値を受け取ったらEntityCollection、それをフィルタリングしたい。

var filtered = from entity in EntityCollection
                       where entity.Key == entityId
                       select entity.Value;

今私は欲しいだけentity.valueです。だから私は変数を作成しました:

List<Dictionary<string, string>> entityDetails = new List<Dictionary<string, string>>();

filteredにキャストするにはどうすればよいentityDetailsですか?

で試しましfiltered.ToList<Dictionary<string, string>>たが、成功しませんでした。

4

1 に答える 1

2

Dictionaryあなたのような LINQ を使用する代わりに、から直接取得できます。

List<Dictionary<string, string>> entityDetails = EntityCollection[entityId];

または、辞書にキーがない場合に最初のアプローチからの例外を回避したい場合

List<Dictionary<string, string>> entityDetails;
if (EntityCollection.TryGetValue(entityId, out entityDetails))
{
}
于 2012-10-27T07:41:12.133 に答える