更新时间: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.