How do I create a List of Dictionaries in .NET?

前端 未结 4 2048
清酒与你
清酒与你 2021-02-04 08:42

I am trying to create a List of Dictionary items. I am not sure how to add items in list and how to get back the values while traversing the list.

4条回答
  •  误落风尘
    2021-02-04 08:58

       // Try KeyValuePair Please.. Worked for me
    
    
        private List> return_list_of_dictionary()
        {
    
            List> _list = new List>();
    
            Dictionary _dictonary = new Dictionary()
            {
                {"Key1",1},
                {"Key2",2},
                {"Key3",3},
            };
    
    
    
            foreach (KeyValuePair i in _dictonary)
            {
                _list.Add(i);
            }
    
            return _list;
    
        }
    

提交回复
热议问题