'Convert' Dictionary into List<object>

前端 未结 9 1974
感情败类
感情败类 2021-02-20 16:12

I have a Dictionary dictionary1 and I need to convert it into a List where Data has the properties lab

9条回答
  •  野性不改
    2021-02-20 16:32

    Assuming:

    class Data
    {
        public string Label { get; set; }
    
        public int Value { get; set; }
    }
    

    Then:

    Dictionary dic;
    List list = dic.Select(p => new Data { Label = p.Key, Value = p.Value }).ToList();
    

提交回复
热议问题