在下面的示例中...由于该类具有 IDisposable 接口,并且该类本身只是一个管理内存对象(不是非托管内存),因此在下面的脚本中(参见案例#1和案例#2) -使用列表对象完成处理后,正确的处理方法是什么?
public class VehicleA : IDisposable
{
public void Dispose() { }
public string Year {get;set;}
public string Make {get;set;}
public string Model {get;set;}
}
public class repositoryVehicle()
{
public List<VehicleA> VehicleLookup()
{
List<VehicleA> returnVehicles = new List<Vehicle>();
returnVehicles.Add(new VehicleA { Year="2007", Make="Ford", Model="Mustang" });
returnVehicles.Add(new VehicleA { Year="2004", Make="Chevy", Model="Blazer" });
return returnVehicles;
}
}
//Case #1...
foreach(var v in repositoryVehicle.VehicleLookup())
{
//v.Year...
}
//Case #2...
List<VehicleA> vehicles = new List<VehicleA>();
vehicles = repositoryVehicle.VehicleLookup();
//vehicles[x].Year...