linq获取数组元素查询

时间:2014-04-02 12:14:33

标签: c# linq lambda

我想仅使用array的元素创建一个dictionary值,其值等于零。

Dictionary<string, int> dict = new Dictionary<string, int>();
int notZeroValues = dict.Values.ToArray();  //sth here to get these elements efficiently

请帮帮忙?

1 个答案:

答案 0 :(得分:2)

dict.Where(x => x.Value != 0).Select(x => x.Value).ToArray();

另一种方式:

dict.Values.OfType<int>().Where(x => x != 0).ToArray();
相关问题