'Convert' Dictionary into List<object>

前端 未结 9 1879
感情败类
感情败类 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:36

        public class Data
        {
            public string Key { get; set; }
    
            public int Value { get; set; }
        }
    
        private static void Main(string[] args)
        {
            Dictionary dictionary1 = new Dictionary();
            dictionary1.Add("key1", 1);
            dictionary1.Add("key2", 2);
    
            List data = dictionary1.Select(z => new Data { Key = z.Key, Value = z.Value }).ToList();
    
            Console.ReadLine();
        }
    

提交回复
热议问题