Rik
Rik

Reputation: 1987

Get List of Dicionary Value Property in c# using List of Keys

I have a dictionary of Guid, Asset and I'd like to get the names from a list of keys that I have:

Dictionary<Guid, Asset> assetDict;

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

From these Guid's I'd like to get all the Asset.name properties, namely a list of

assetDict[selectedAssetGuid].name

where selectedAssetGuid is one element in selectedAssetGuidList. Thanks Y'all

Upvotes: 1

Views: 56

Answers (1)

Ousmane D.
Ousmane D.

Reputation: 56469

Method syntax:

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

or query syntax:

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

Upvotes: 2

Related Questions