Get first key from Dictionary

后端 未结 5 1639
你的背包
你的背包 2020-12-24 10:34

I\'m using a System.Collections.Generic.Dictionary.

I want to return the first key from this dictionary. I tried dic.Keys[0]

5条回答
  •  -上瘾入骨i
    2020-12-24 11:20

    we can using linq technology

    var key = dic.Take(1).Select(d => d.Key).First()
    

    or we can use another search

    var myList = dic.Take(1).Where(d => d.Key.Contains("Heaven")).ToList();
    

提交回复
热议问题