views:

21

answers:

1

OK so my question is self explanatory, here is some code so you can understand a little more.

public Dictionary<string,VcardWindow> VcardWindowManager 
    = new Dictionary<string,VcardWindow>();'

And access like so:

public void ShowVcardWindow(string VcardOwner)
{
   VcardWindow Window;
   if(VcardWindowManager.ContainsKey(VcardOwner))
   {
      Window = VcardWindowManager[VcardOwner];
   }
   else
   {
       Window = new VcardWindow(VcardOwner);
       //Startup Code
       VcardWindowManager.Add(VcardOwner,Window);
   }
   //Invoker here
}

Is by storing windows in a dictionary OK? Are there other means that are faster and safer?

+1  A: 

An instance of a Form is an object like any other, and so you can store its reference in a Dictionary. Using a Dictionary in this case is the correct way to store a collection of objects that need to be accessed according to a key, in a single-threaded scenario.

Allon Guralnek
That was my assumption but in the world of C# not all is as it seems. thought I would clarify. Thanks
RobertPitt