【问题标题】:Get List of Dicionary Value Property in c# using List of Keys使用键列表在c#中获取字典值属性列表
【发布时间】:2018-04-22 21:53:44
【问题描述】:

我有一本 Guid、Asset 的字典,我想从我拥有的键列表中获取名称:

Dictionary<Guid, Asset> assetDict;

List<Guid> selectedAssetGuidList;  //subset of assetDict.Keys

我想从这些 Guid 中获取所有 Asset.name 属性,即列表

assetDict[selectedAssetGuid].name

其中 selectedAssetGuid 是 selectedAssetGuidList 中的一个元素。谢谢大家

【问题讨论】:

  • 你的意思是var enumerableWithNames = selectedAssetGuidList.Select(guid =&gt; assetDict[guid].name);

标签: c# linq dictionary


【解决方案1】:

方法语法:

var result = selectedAssetGuidList.Select(guid => assetDict[guid].name);

或查询语法:

var result = from guid in selectedAssetGuidList
             select assetDict[guid].name;

【讨论】:

    猜你喜欢
    • 2013-08-29
    • 1970-01-01
    • 1970-01-01
    • 2019-03-27
    • 2020-08-06
    • 1970-01-01
    • 2020-03-31
    • 2011-11-08
    相关资源
    最近更新 更多