2016-10-12 32 views
-2
class Program 
{ 
    List<int> ages = new List<int>(); 

不能访问里面的其他方法,请告诉我为什么? 我遇到错误信息cs0120“A对象引用需要非静态字段,方法或属性‘program.ages’”无法将列表声明为全局变量?

感谢

+0

你如何*尝试*访问它?您描述的错误指向您未显示的一行代码。提供*完整*和*最小*示例。 – David

回答

1

更改您的列表声明staticpublic

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

    // other method and stuff you want 
}