Custom iterator for dictionary?

Posted by aaginor on Stack Overflow See other posts from Stack Overflow or by aaginor
Published on 2010-04-21T14:27:24Z Indexed on 2010/04/21 14:33 UTC
Read the original article Hit count: 205

Filed under:
|
|

Hi folks,

in my C#-Application, I have a Dictionary object. When iterating over the object using foreach, I naturally get each element of the dictionary. But I want only certain elements to be iterated, depending on the value of a property of MyValue.

class MyValue
{
  public bool AmIIncludedInTheIteration { get; set; }
  ...
}

Whenever AmIIncludedInTheIteration is false, the item shall not be returned by foreach. I understand that I need to implement my own iterator and override the Dictionary-Iterator somewhere. Can anyone here give me a short HowTo?

Thanks in advance, Frank

© Stack Overflow or respective owner

Related posts about c#

Related posts about dictionary