Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7944429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:32:54+00:00 2026-06-04T00:32:54+00:00

I have got the problem with creating an array list in c#, Can you

  • 0

I have got the problem with creating an array list in c#, Can you please help me.
I need to create the array list to remove all the pipes that have lengths lower than 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;
        }
    }


}

I have created the two classes called Pipe and PipeList as well and I need to place the array list in the “RemoveTheSmallPipes” method. But I am confused now to write the rest. Please help me to remove all the pipes that have lengths lower than 19.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:32:55+00:00Added an answer on June 4, 2026 at 12:32 am

    Here’s your method without changing anything else:

    public static ArrayList RemoveTheSmallPipes(ArrayList lstPipeTypes)
    {
    
        for (int i = 0; i < lstPipeTypes.Count; i++)
        {
            ArrayList pipesToRemove = new ArrayList();
            int pipeCount = ((PipesList)lstPipeTypes[i]).Pipes.Count;
            for (int j = 0; j < pipeCount; j++)
            {
                if (((Pipe)((PipesList)lstPipeTypes[i]).Pipes[j]).length < 19)
                {
                    pipesToRemove.Add(j);
                }
            }
    
            for (int k = 0; k < pipesToRemove.Count; k++)
            {
                ((PipesList)lstPipeTypes[i]).Pipes.RemoveAt((int)pipesToRemove[k]);
            }
        }
    
        return lstPipeTypes;
    }
    

    It’s really a shame You cannot change anything else because this code is not up to standards anymore. To show You a difference here’s modified C# 4.0 version:

    Console:

    static void Main(string[] args)
    {
        var pipeTypes = new List<PipePile>();
    
        pipeTypes.Add(new PipePile("PVC Pipes", new List<Pipe>
            {
                new Pipe { Name = "The blue pipe", Length = 12 },
                new Pipe { Name = "The red pipe", Length = 15 },
                new Pipe { Name = "The silver pipe", Length = 6 },
                new Pipe { Name = "The green pipe", Length = 52 }
            }));
    
        pipeTypes.Add(new PipePile("Iron Pipes", new List<Pipe>
            {
                new Pipe { Name = "The gold pipe", Length = 9 },
                new Pipe { Name = "The orange pipe", Length = 115 },
                new Pipe { Name = "The pink pipe", Length = 1 }
            }));
    
        pipeTypes.Add(new PipePile("Chrome Pipes", new List<Pipe>
            {
                new Pipe { Name = "The grey pipe", Length = 12 },
                new Pipe { Name = "The black pipe", Length = 15 },
                new Pipe { Name = "The white pipe", Length = 19 },
                new Pipe { Name = "The brown pipe", Length = 60 },
                new Pipe { Name = "The peach pipe", Length = 16 }
            }));
    
        // Remove all pipes with length longer than 19
        pipeTypes.ForEach(pile => pile.Pipes.RemoveAll(pipe => pipe.Length > 19));
    }
    

    Classes:

    public class Pipe
    {
        public string Name { get; set; }
        public float Length { get; set; }
    }
    
    public class PipePile
    {
        public string PipeType { get; set; }
        public List<Pipe> Pipes { get; set; }
    
        public PipePile(string pipeType, List<Pipe> pipes)
        {
            PipeType = pipeType;
            Pipes = pipes;
        }
    
        public PipePile(): this("", new List<Pipe>())
        {
        }
    }
    

    As You can see it’s quite different, but much more elegant (Linq FTW! 🙂 )

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got a new problem .. I can't fix it .. I create
So I got a problem that I can't wrap my mind around. I'm creating
I've got a SharePoint problem which I need some help with. I'm creating some
I have got a performance problem about TextField.htmlText +=msg .And I know that TextField.appendText(msg)
Can't understand what is a problem here: I have got main.cpp file where I
I've got a problem I can't find any solution for. I have a textfile
I'm creating a simple shop, but have run into a simple problem.. I've got
I am creating a registration form, but I have got one problem only... why
I have got a problem with calling a global function, which takes a pointer
I have got a strange problem about in_array recently which I cannot understand. e.g.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.