且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

名称"..."在当前上下文中不存在

更新时间:2023-02-16 15:16:20

dogList对于方法Main是本地的.相反,您要做的是将dogList放置在该范围之外.

dogList is local to the method Main. What you want to do instead is to place dogList outside of that scope.

public class Program
{
    static List<Dog> dogList = new List<Dog>();

...

或者,您也可以将列表发送到添加方法中.

Alternately you can send the list into your add method.