javaid nazim

javaid nazim

  • NA
  • 2
  • 3.2k

Want to remove the pipeline who length is less than 19 through for loop or while loop?

May 30 2012 10:30 AM
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;
        }
    }


}