convert HashTable to Dictionary in C#

前端 未结 5 1794
闹比i
闹比i 2020-12-15 03:23

how to convert a HashTable to Dictionary in C#? is it possible? for example if I have collection of objects in HashTable and if I want to convert it to a dictionary of objec

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-15 04:23

    var table = new Hashtable();
    
    table.Add(1, "a");
    table.Add(2, "b");
    table.Add(3, "c");
    
    
    var dict = table.Cast().ToDictionary(d => d.Key, d => d.Value);
    

提交回复
热议问题