c# dictionaries intersect

前端 未结 4 481
北海茫月
北海茫月 2021-01-01 20:48

I have a question about Linq / Lambda and the following issue:

I have two dictionaries, primary and secondary... These two dictionaries are defined as Key=string, Va

4条回答
  •  情话喂你
    2021-01-01 21:09

    You can still use primaryDict within your Linq statement since you are creating a new dictionary, which only gets assigned to your variable once it is created:

    resultDict = primaryDict.Keys
                            .Intersect(secondaryDict.Keys)
                            .ToDictionary(t => t, primaryDict[t]);
    

提交回复
热议问题