Array List Global Variable

  • Thread starter Thread starter Phenix Smith
  • Start date Start date
P

Phenix Smith

I am looking at coverting an application over to C#. Currently I have a
global list varible that needs to be converted. I have tested different
ideas to accomplish the same idea. Ths best way I have found for me is to
create a configuration class with a static array list that is accessed
through static methods. Is there a better way to handle this. This class
is in a DLL if that makes a difference.

public class Configuration
{
private static ArrayList _arraylist;
private static ArrayList List
{
get
{
if (_arraylist == null)
_arraylist = new ArrayList();
return _arraylist;
}
}

public static int Add(string Name, string Value)
{
return List.Add(Name +"="+Value);
}
}
 
You should/could make this Configuration class a Singleton otherwise you
could end up with multiple copies of it running around. Then you do not
make the array list static but you force the user to obtain the Single
instance of the class. If you are not familiar with Singletons there are
some very good examples of how to implement one. Just do a google search
and you will find a lot..

JIM
 
Back
Top