Make ArrayList accessible from whrever in the program

  • Thread starter Thread starter tiger79
  • Start date Start date
T

tiger79

Hi,
I have placed the next code :

ArrayList myAL = new ArrayList();



right after the InitializaComponent. I'd like to be able to add objects to
this arraylist from anywhere in the program (so also in a buttonClick
event). I have tried placing public in front of it but that won't work. How
do I manage to obtain the wanted result ?
 
tiger79 ha scritto:
Hi,
I have placed the next code :

ArrayList myAL = new ArrayList();



right after the InitializaComponent. I'd like to be able to add objects to
this arraylist from anywhere in the program (so also in a buttonClick
event). I have tried placing public in front of it but that won't work. How
do I manage to obtain the wanted result ?

If you declare a variable into a class it belongs to the class.

Probably you need something like

public class MyGlobalInfos
{

sealed ArrayList myAL = new ArrayList;

public sealed ArrayList MyArrayList()
{
get { return myAL; }
}
}

And then access it with

MyGlobalInfos.MyArrayList

Bye
 
Create a class and make a property that's public and static and of type
arraylist. Set this property equal to that value.

Or, create a single instance class and just reference it directly:
sealed class PatientInfo
{
public static readonly PatientInfo Instance = new PatientInfo();
}

add a property inside your class for hte arraylist. Then you'll reference
it ClassName.Instance.PropertyName

Either one will get you there.

HTH,

Bill
 
Grazie Zanna :D
I have managed in another way by placing the needed data directly into the
object so that I can call it without using an ArrayList...

Thanx to William as well...

Ci si becca alla prossima domanda Zanna ;)
 
Back
Top