我正在关注这个 C# 教程http://csharp-station.com/Tutorial/CSharp/Lesson20,这是一个初学者问题。
下面我正在创建一个新的字典集合客户的客户公共但不是静态类。简单的问题是我不能在我的方法中使用该customers.Add
行。static void main
我在这里想念什么?客户也必须是静态的吗?我应该在这里做什么才能创建客户对象。
Dictionary<int, Customer> customers = new Dictionary<int, Customer>();
Customer cust1 = new Customer(1, "Cust 1");
Customer cust2 = new Customer(2, "Cust 2");
Customer cust3 = new Customer(3, "Cust 3");
customers.Add(cust1.ID, cust1);
customers.Add(cust2.ID, cust2);
customers.Add(cust3.ID, cust3);
foreach (KeyValuePair<int, Customer> custKeyVal in customers)
{
Console.WriteLine(
"Customer ID: {0}, Name: {1}",
custKeyVal.Key,
custKeyVal.Value.Name);
}