How do I search for values in a dictionary

Posted by fishhead on Stack Overflow See other posts from Stack Overflow or by fishhead
Published on 2010-06-08T19:48:56Z Indexed on 2010/06/08 19:52 UTC
Read the original article Hit count: 193

Filed under:

what would be the best way to search for a value in a dictionary. for instance I would like to search for modified objects, would going through the entire collection be the only way to do this?

c#, .net 2.0

class RecA
 { 
 public bool modified {get;set:}
 public string{get;set;}
 }

class RecA_Dic : Dictionary<int,Rec_A>
{

   public bool GetItemByKey(int key,out obj)
   {
    return   this.TryGetValue(key, out obj);
    }

   public List<Rec_A> getModifiedItems()
   {
     List<Rec_A> li = new List<Rec_A>();
     for(int i=0;i<this.count;i++)
      if (((Rec_A)this[i]).modified == true)
       li.Add((Rec_A)this[i]);
     return li;
   }

}

© Stack Overflow or respective owner

Related posts about c#