我在 C# 中创建数组列表时遇到了问题,你能帮帮我吗?我需要创建数组列表来删除所有长度小于 19 的管道。
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ArrayList lstPipeTypes = new ArrayList();
lstPipeTypes.Add(new PipesList("PVC Pipes"));
((PipesList)lstPipeTypes[0]).Pipes.Add(new Pipe("The blue pipe", 12));
((PipesList)lstPipeTypes[0]).Pipes.Add(new Pipe("The red pipe", 15));
((PipesList)lstPipeTypes[0]).Pipes.Add(new Pipe("The silver pipe", 6));
((PipesList)lstPipeTypes[0]).Pipes.Add(new Pipe("The green pipe", 52));
lstPipeTypes.Add(new PipesList("Iron Pipes"));
((PipesList)lstPipeTypes[1]).Pipes.Add(new Pipe("The gold pipe", 9));
((PipesList)lstPipeTypes[1]).Pipes.Add(new Pipe("The orange pipe", 115));
((PipesList)lstPipeTypes[1]).Pipes.Add(new Pipe("The pink pipe", 1));
lstPipeTypes.Add(new PipesList("Chrome Pipes"));
((PipesList)lstPipeTypes[2]).Pipes.Add(new Pipe("The grey pipe", 12));
((PipesList)lstPipeTypes[2]).Pipes.Add(new Pipe("The black pipe", 15));
((PipesList)lstPipeTypes[2]).Pipes.Add(new Pipe("The white pipe", 19));
((PipesList)lstPipeTypes[2]).Pipes.Add(new Pipe("The brown pipe", 60));
((PipesList)lstPipeTypes[2]).Pipes.Add(new Pipe("The peach pipe", 16));
RemoveTheSmallPipes(lstPipeTypes);
}
public static ArrayList RemoveTheSmallPipes(ArrayList lstPipeTypes)
{
//should remove all pipes that have lengths lower than 19.
return lstPipeTypes;
}
}
class PipesList
{
public string pipeType;
public ArrayList Pipes;
public PipesList(string newBoxType)
{
pipeType = newBoxType;
Pipes = new ArrayList();
}
}
class Pipe
{
public string name;
public float length;
public Pipe(string newName, float newLength)
{
this.name = newName;
this.length = newLength;
}
}
}
我还创建了两个名为 Pipe 和 PipeList 的类,我需要将数组列表放在“RemoveTheSmallPipes”方法中。但是我现在很困惑,无法写剩下的。请帮我移除所有长度小于 19 的管道。