1

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?

1
  • is that a typo ? you mean values are not equal to zero? Commented Apr 2, 2014 at 12:18

1 Answer 1

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

Another way:

dict.Values.OfType<int>().Where(x => x != 0).ToArray();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.