Okay, I have looked for this one, but I can't seem to find it anywhere. How can I make a list publicly accessible? I have tried the regular way:
class Program
{
public static void Main()
{
public List<string> listAges = new List<string>();
...but that just gives me two errors.
The error on public = "invalid expression term 'public'"
The error on List = "; expected"
Did I skip a page or something? Can I not make a public list?
AnthonyPosted Sep 1, 2008, 3:15 AM
Well, Alan, you sure do like to pull my butt out of the fire lately. Thanks again. I'll probably have another question within the next few days, but I'll hold off as long as I can.
AlanPosted Aug 31, 2008, 12:55 PM
You've got it the wrong way around - it should be:
class Program
{
public static List listAges = new List();
public static void Main()
{
The way you had it, listAges was a local variable rather than a field and local variables are always implicitly private to the method they're declared in - you can't use an access modifier such as public with them.
I'd also make it static so you can access it with the expression
Program.listAges from anywhere within the application without the need to create a Program instance.