How to insert element in first index in dictionary?

前端 未结 9 1030
被撕碎了的回忆
被撕碎了的回忆 2020-12-17 10:09

Is there a method or technique that allows you to insert an element into a Dictionary guaranteeing that the item is in the first index of t

9条回答
  •  南方客
    南方客 (楼主)
    2020-12-17 10:33

    I know it is a three years old question. But found a workaround of this problem. It may help someone

    Dictionary dic = foo.GetOutput();
    
    dic = (new Dictionary {{"key","value"}}).Concat(dic).ToDictionary(k => k.Key, v => v.Value);
    

    This will insert the element in the beginning of dictionary :)

提交回复
热议问题