Tag: 公开

当前上下文中不存在名称“…”

我在Main()有一个列表,我正在尝试从变量中添加一个项目到该列表。 但它正在抛出错误“名称’dogList’在当前上下文中不存在” 在我的addDog()方法中,由于上面的原因, dogList.Add()无法正常工作。 namespace DoggyDatabase { public class Program { public static void Main(string[] args) { // create the list using the Dog class List dogList = new List(); // Get user input Console.WriteLine(“Dogs Name:”); string inputName = Console.ReadLine(); Console.WriteLine(“Dogs Age:”); int inputAge = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(“Dogs Sex:”); string inputSex = Console.ReadLine(); Console.WriteLine(“Dogs Breed:”); string […]