Reputation: 2496
I would like to create an array
of values only with elements of my dictionary
which values is equal zero.
Dictionary<string, int> dict = new Dictionary<string, int>();
int notZeroValues = dict.Values.ToArray(); //sth here to get these elements efficiently
Please help?
Upvotes: 1
Views: 76
Reputation: 101681
dict.Where(x => x.Value != 0).Select(x => x.Value).ToArray();
Another way:
dict.Values.OfType<int>().Where(x => x != 0).ToArray();
Upvotes: 2