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 4078958
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:44:22+00:00 2026-05-20T17:44:22+00:00

I am having troubling reading my values out of an ArrayList. The compiler goes

  • 0

I am having troubling reading my values out of an ArrayList. The compiler goes into the ReadOutFromArray function, but skips the Console.WriteLine(st)? Can anyone tell me where I went wrong. Been on it for a couple of hours chasing my tail. Thanks.

using System;
using System.IO;
using System.Collections.Generic;
using System.Collections;
using System.Text;

namespace BoolEx
{
    class Program
    {
        static void Decision(ArrayList decis)
        {
            bool ans = true;

            decis = new ArrayList();
            //ArrayList aList = new ArrayList();
            while (ans)
            {
                Console.WriteLine("1=True 0=False");
                int x = Int32.Parse(Console.ReadLine());

                if (x == 1)
                {
                    ans = true;
                }
                else
                {
                    ans = false;
                }

                if (ans == true)
                {
                    ReadInArray(decis);
                }
                else
                {

                    ReadOutArray(decis);
                }
            }
        }
        static void ReadInArray(ArrayList f)
        { 
            f= new ArrayList();
            Console.WriteLine("Enter in a name");
            f.Add(Console.ReadLine());
        }

        static void ReadOutArray(ArrayList d)
        {
            d = new ArrayList();
            ReadInArray(d);

            foreach (string st in d)
            {
                Console.WriteLine(st);
            }
        }

        static void Main(string[] args)
        { 
            ArrayList g = new ArrayList();
            Decision(g);
        }
    }
}
  • 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-05-20T17:44:23+00:00Added an answer on May 20, 2026 at 5:44 pm

    Although I do agree with everything Skeet has mentioned, it appears the poster is trying to understand some things and I think
    Jon might have missed that.

    First if all you want to do is fill a list and print it try this:

    static void (main)
     {
       ArrayList l = new ArrayList();
       FillMyList(l);
       DisplayMyList(l);
     }
    
    public static void FillMyList(ArrayList temp)
     {
      for(int i = 0; i < 10; i++)
         temp.Add(i);
     }
    
    public static void DisplayMyList(ArrayList temp)
     { 
     foreach(int i in temp)
      Console.WriteLine(i);
     }
    

    Second thing is take what Jon Skeet has mentioned and definately understand some things. Booleans are just true / false (unless you introduce the nullable types) but for now keep it simple.
    ArrayList is really old school, it kind of suffers like the HashTable in that you can easily run into trouble adding different data types into the object (read up on boxing of data types and unboxing).
    Finally, you should really replace anything with this System.Collection.ArrayList to System.Collections.Generic.List.

    The list class is a generic class and is made available so that you don’t have to deal with the issues that you could encounter when dealing with array lists or hash tables.

    Edit

    I noticed you were asking users to add items to the list. You can do this using a do while loop instead of the for loop I posted, something to this effect (note i have not tested any of this):

    public static void FillMyList(ArrayList temp)
     {
      char c='y';
    
      do {
         Console.WriteLine("Enter a value");
         int x = Int32.Parse(Console.ReadLine());  
         temp.Add(x);
         Console.WriteLine("Continue adding numbers to list, if so type y");
         char c = Console.ReadLine();
      }while(c=='y' || c=='Y');
     }
    

    Again I am just giving you examples here, you will have to handle user input in case someone doesn’t enter the correct information, exceptions, etc.

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

Sidebar

Related Questions

So I've done some looking online and throught the documentation, but I'm having troubling
I am having troubling figure out error on following code DECLARE CR_QUERY INTEGER; CR_HANDLE
Grettings!. I am having too much troubling with the following question... i will try
Having trouble with each function... Will try to explain by example... In my code,
Having trouble with an .htaccess file on WAMP. Works on the live server, but
I'm having troubling linking a program with sqlite3. Any ideas? gcc -g -O2 main.o
Having some trouble w/ IE7. IE8, Chrome, Firefox all work fine, but IE7 won't
I'm having a rather heated debate into IE's XHTML Compatibility. The only thing is,
Having used New Relic before, I know it can measure performance but it's an
I am having troubling adding nil at the end of an array, I get

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.