How to achieve Global scope of arraylists

  • Thread starter Thread starter ree
  • Start date Start date
R

ree

I am new to c#

Since you cant use vectors in it.
I was trying to use an arraylist, but the problem is how do I get an
arraylist to have a global scope. I.e. accessing the arraylist of objects
in different dialog boxes.

Thanks
 
Hi,
Keep the array list in a seperate class, and make the array list public
static. Then you can access it like this


MySeperateClass.MyArrayList = new System.Collections.ArrayList();
MySeperateClass.MyArrayList.Add("Hello");
Console.WriteLine(MySeperateClass.MyArrayList[0]);

public class MySeperateClass
{
public static System.Collections.ArrayList MyArrayList;
}


-benny
 
You could also just make the arraylist public in your form or make a public
property to the private var without needing another class.
 

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

Back
Top