If you're using C# 3.0 or better...
using System.Linq;
public Car[] Filter(Car[] input)
{
return input.Where(c => c.IsAvailable).ToArray();
}
And if you don't have access to LINQ (you're using an older version of .NET)...
public Car[] Filter(Car[] input)
{
List<Car> availableCars = new List<Car>();
foreach(Car c in input)
{
if(c.IsAvailable)
availableCars.Add(c);
}
return availableCars.ToArray();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…