TestModel类定义:

public class TestModel
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Code { get; set; }

}

 

Dictionary与List定义:

List<TestModel> list = new List<TestModel>();
Dictionary<int, TestModel> dict = new Dictionary<int, TestModel>();

 

Dictionary转List:

dict = list.ToLookup(item=> item.Id).ToDictionary(item=> item.Key, item=> item.First());

 

List转Dictionary

list = dict.Values.ToList();

 

高效查找:

foreach (TestModel item in list)
{
    if (dict.ContainsKey(item.Id))
    {
        TestModel model = dict[item.Id];
    }
}

 

相关文章:

  • 2022-12-23
  • 2022-02-05
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
猜你喜欢
  • 2022-12-23
  • 2021-08-31
  • 2019-05-17
  • 2022-12-23
  • 2021-11-21
相关资源
相似解决方案