0
class Program
{
    List<int> ages = new List<int>();

Cant be access inside of other methods, please tell me why? I get error message cs0120 "A object reference is required for the non-static field, method or property 'program.ages'"

Thanks

Adam
  • 482
  • 1
  • 8
  • 18
  • How are you *trying* to access it? The error you describe is pointing to a line of code you're not showing. Provide a *complete* and *minimal* example. – David Oct 12 '16 at 17:54

1 Answers1

2

Change your list declaration static and public

class Program
{
   public static List<int> ages = new List<int>();

   // other method and stuff you want
}
Mostafiz
  • 7,243
  • 3
  • 28
  • 42