Har*_*shi 0 .net c# linq dictionary
我有一系列字典如下:
Dictionary<int, int>[] matrix = new Dictionary<int, string>[10];
Run Code Online (Sandbox Code Playgroud)
我需要保存在这本字典中的所有密钥,我在foreach循环中使用如下:
foreach (int key in matrix.Keys)
{
}
Run Code Online (Sandbox Code Playgroud)
显然,matrix.Keys这里不行.那么,有没有办法获得字典的所有键而不循环整个数组(也许Linq或某事)?
使用LINQ SelectMany:
var keys = matrix.SelectMany(x => x.Keys);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
77 次 |
| 最近记录: |