【发布时间】:2015-10-14 01:01:05
【问题描述】:
我必须上课,Custom Car Factory Class 和 Custom Car Factory,我正在尝试通过使用 foreach 来从定制汽车工厂注销 Custom Car 以获取工厂中的所有数据,但是我收到“foreach”错误语句不能对变量 CustomCarFactory 进行操作,因为 Custom CarFactory 不包含“GetEnumerator”的公共定义”
定制汽车工厂类
[CustomCarFactory.cs]
internal class CustomCarFactory : ICarFactory
public CustomCarFactory(string make, string model, string serial, string plate)
{
Make = make;
Model = model;
Serial = serial;
Plate = plate;
}
internal string Make;
internal string Model;
internal string Serial;
internal string Plate;
Car Library Implementation class
[CarLibraryImplementation.cs]
internal static List<ICarFactory> CarFactories= new List<ICarFactory>();
在这部分我将它注册到自定义工厂
private static CustomCarFactory factory = new CustomCarFactory(string.Empty, string.Empty, string.Empty, string.Empty);
private static void registerCarImplementation(string make, string model, string serial, string plate)
{
factory = new CustomCarFactory(make, model, serial, plate);
CarFactories.Add(factory);
然后在这一部分中,我将从自定义工厂中注销它,但我得到“foreach 语句无法对变量 CustomCarFactory 进行操作,因为 Custom CarFactory 不包含 'GetEnumerator' 的公共定义”
private static void UnregisterCarImplementation(string make, string model, string serial, string plate)
{
foreach (var item in factory)
{
// Get make from current factory
// Get model from current factory
}
}
【问题讨论】:
-
您是不是要迭代
CarFactories而不是factory? -
抱歉,是的。