Gra*_*per 34 c# asp.net oop collections dictionary
我检查是否有任何方法可以将所有键都返回到数组而不使用for each循环(我没有使用每个循环的约束我只是看其他任何方式)
提前致谢
Luk*_*keH 69
我不确定你的措辞是否需要键或值.无论哪种方式,它都非常简单.使用字典的Keysor Values属性和ToArray扩展方法.
var arrayOfAllKeys = yourDictionary.Keys.ToArray();
var arrayOfAllValues = yourDictionary.Values.ToArray();
Run Code Online (Sandbox Code Playgroud)
您想要键还是值?
你可以获得这样的钥匙:
dictionary.Keys.ToArray();
Run Code Online (Sandbox Code Playgroud)
你可以获得这样的值;
dictionary.Values.ToArray();
Run Code Online (Sandbox Code Playgroud)
此 ToArray 方法来自 System.Linq.Enumerable。
| 归档时间: |
|
| 查看次数: |
47733 次 |
| 最近记录: |