第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 LINQ 將屬性值與字典鍵匹配

使用 LINQ 將屬性值與字典鍵匹配

C#
慕森王 2023-09-16 15:56:53
假設我有這兩個簡單的類:public class MyObject{    public string name;    public string objectProperty;    [other properties]}public class Referencer{    public string name;    public Dictionary<string, object> objectDictionary;}和 MyObject 實例的列表:List<MyObject> myObjects = new List<MyObject>{    new MyObject(name: "name1", objectProperty: "objectProperty1", other properties...),    new MyObject(name: "name2", objectProperty: "objectProperty2", other properties...),    new MyObject(name: "name3", objectProperty: "objectProperty3", other properties...),    other myObjects...}以及這樣的字典字典:Dictionary<string, Dictionary<string, object>> sampleDictionary = new Dictionary<string, Dictionary<string, object>>{    {"name3", new Dictionary<string, object> { {"property1", "value1"}, {"property2", "value2"}  }  },    {"name2", new Dictionary<string, object> { {"property3", "value3"}, {"property4", "value4"}  }  },    {"name1", new Dictionary<string, object> { {"property5", "value5"}, {"property6", "value6"}  }  },    other entries...};我需要能夠根據(jù)規(guī)則創(chuàng)建List<Referencer>匹配:myObjectssampleDictionarymyObjects.name == sampleDictionary.Key我嘗試過使用 LINQ ForEach, Where, ToDictionary,但我認為我這里缺少一些東西,需要你的幫助。
查看完整描述

1 回答

?
偶然的你

TA貢獻1841條經(jīng)驗 獲得超3個贊

稍微擴充一下:

myObjects
????.Where(x?=>?sampleDictionary.ContainsKey(x))
????.Select(x?=>?new?Referencer?{?name?=?x.name,?objectDictionary?=?sampleDictionary[x.name]?});



查看完整回答
反對 回復 2023-09-16
  • 1 回答
  • 0 關注
  • 108 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號