Array List Global Variable

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);
}
}
 
J

James

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top