更新时间:2021-11-16 08:52:16
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>();
...
或者,您可以将列表发送到您的 add 方法中.
Alternately you can send the list into your add method.