javaid nazim

javaid nazim

  • NA
  • 2
  • 3.1k

here custum generic list , I want to remove all pipelist who value is small in arraylist through the for loop and display in the main method ?

May 30 2012 7:18 PM
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{


List<PipesList> lstPipeTypes = new List<PipesList>();


lstPipeTypes.Add(new PipesList("PVC Pipes"));
lstPipeTypes[0].Pipes.Add(new Pipe("The blue pipe", 12));
lstPipeTypes[0].Pipes.Add(new Pipe("The red pipe", 15));
lstPipeTypes[0].Pipes.Add(new Pipe("The silver pipe", 6));
lstPipeTypes[0].Pipes.Add(new Pipe("The green pipe", 52));

lstPipeTypes.Add(new PipesList("Iron Pipes"));
lstPipeTypes[1].Pipes.Add(new Pipe("The gold pipe", 9));
lstPipeTypes[1].Pipes.Add(new Pipe("The orange pipe", 115));
lstPipeTypes[1].Pipes.Add(new Pipe("The pink pipe", 1));

lstPipeTypes.Add(new PipesList("Chrome Pipes"));
lstPipeTypes[2].Pipes.Add(new Pipe("The grey pipe", 12));
lstPipeTypes[2].Pipes.Add(new Pipe("The black pipe", 15));
lstPipeTypes[2].Pipes.Add(new Pipe("The white pipe", 19));
lstPipeTypes[2].Pipes.Add(new Pipe("The brown pipe", 60));
lstPipeTypes[2].Pipes.Add(new Pipe("The peach pipe", 16));


lstPipeTypes = RemoveTheSmallPipes(lstPipeTypes);

foreach (var pipeList in lstPipeTypes)
{
Console.WriteLine("PipesList: {0}", pipeList.pipeType);

foreach (var pipe in pipeList.Pipes)
{
Console.WriteLine("{0}, length: {1}", pipe.name, pipe.length);
}
Console.WriteLine();
}
Console.WriteLine("this is pipelinelenght{0}", lstPipeTypes.Count);

Console.WriteLine("Done, press return to exit");
Console.ReadLine();
}


public static List<PipesList> RemoveTheSmallPipes(List<PipesList> lstPipeTypes)
{
int a = 19;



//The method RemoveTheSmallPipes is meant to get rid of all of the pipes with lengths less than 19.
//Please add the code into this method to search through the ArrayList of PipeList, and remove the small pipes from them

for (int i = 0; i < lstPipeTypes.Count; i++)
{

if (lstPipeTypes[i].Pipes )
{

}



return lstPipeTypes;

}

}

class PipesList
{
public string pipeType;
public List<Pipe> Pipes;

public PipesList(string newBoxType)
{
pipeType = newBoxType;
Pipes = new List<Pipe>();
}
}

class Pipe
{
public string name;
public float length;

public Pipe(string newName, float newLength)
{
this.name = newName;
this.length = newLength;
}
}


}


Answers (1)