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

  • Home
  • SEARCH
  • 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 937629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:30:32+00:00 2026-05-15T21:30:32+00:00

I trying to write an application that has a collection of students using different

  • 0

I trying to write an application that has a collection of students using different types of collections (List, ArrayList, Dictionary)

Requirements:

  1. Use C# Iterators (not FOREACH)
  2. Return IEnumerable of Students

I created a class called Students implementing IEnumerable interface

I have 3 methods for each collection and each returning an IEnunerable of Students

 public class Students : IEnumerable
    {

        //Generic List
        public IEnumerable getList()
        {
            List<string> ListStudents = new List<string>();
            ListStudents.Add("Bob");
            ListStudents.Add("Nancy");
            for (int i = 0; i < ListStudents.Count; i++)
            {
                yield return ListStudents[i];
            }
        }

        //Generic Dictionary
        public IEnumerable getDiction()
        {
            Dictionary<string, string> DicStudents = new Dictionary<string, string>();

            DicStudents.Add("FirstName", "Nana");


            for (int i = 0; i < DicStudents.Count; i++)
            {
                yield return DicStudents.Values.ToList()[i];
            }
        }

        //Array List
        public IEnumerable getArray()
        {
            ArrayList ArrayStudents = new ArrayList { "Tom", "Noah", "Peter" };

            for (int i = 0; i < ArrayStudents.Count; i++)
            {
                yield return ArrayStudents[i];
            }
        }

        public IEnumerator GetEnumerator()
        {


        }

    }

How do I take the 3 collections above and iterate through them as if there were one collection. At the moment, I am putting them into an Array but I cannot seem to iterate through them:

   public class GetALL: IEnumerable
    {
        public IEnumerator GetEnumerator()
        {

            Students s = new Students();

            IEnumerator[] enumerator = new IEnumerator[3] 
            {
                s.getList().GetEnumerator(),
                s.getDiction().GetEnumerator(),
                s.getArray().GetEnumerator(),
            };
             return enumerator[3];
        }
    }

There must be an easier way or a way that it can actually be donw….

Thanks

🙂


Ok I misunderstood the request.

I have the below:

public class Student : IEnumerable
    {
        int ID;
        string Name;
        string Phone;


        public IEnumerable<Student> getStudentList()
        {
            List<Student> e = new List<Student>();
            e.Add(new Student() { Name = "Bob", ID = 20, Phone = "914-123-1234" });
            e.Add(new Student() { Name = "Jack", ID = 21, Phone = "718-123-1234" });
            e.Add(new Student() { Name = "Nancy", ID = 22, Phone = "212-123-1234" });

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

                yield return e[i];

            }
        }
        public IEnumerator GetEnumerator()
        {

        }

    }

How do I return the List of Students and write them to the console? I want to keep my list of students in the Student Object and then iterate through them object and print the list of students?

Is this possible?

  • 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-15T21:30:33+00:00Added an answer on May 15, 2026 at 9:30 pm

    OK, now your Student class is really messed up. AS it is defined, each Student has a list of Students within it.

    You will be needing three classes here:

    • A Student class – Keep the data members (which should be Properties) and get rid of the rest.
    • A Students class – Which you will probably want do implement IList (and probably derived from List

    • A Program class, which will contain your Main() method, and will hold you Students object, and will have the method responsible for putting the Student objects into the Students object.

    Also, note that a List is also an IEnumerable, so your code:

            List<Student> e = new List<Student>();   
            //// blah-blah-blah   
            for (int i = 0; i < e.Count; i++)   
            {   
                yield return e[i];   
            }
    

    Is exactly the same as:

            List<Student> e = new List<Student>();   
            //// blah-blah-blah 
           return e;  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write an android application that has two main activities: login screen
I am trying to write a mobile application that has images instead of buttons
I'm trying to write an application that connects to multiple IPs/ports and the problem
I'm trying to write an application that responds whenever the Shift key is pressed,
I am trying to write an application that performs operations on a grid of
I am trying to write an application that adds data to an exsiting spreadsheet
Hi I am trying to write an application that will play morse code. I
I'm trying to write an application (winforms) that can demonstrate how two oscillating colors
I'm trying to write a javascript application that loads data from the openstreetmap API
I'm trying to write a silverlight application that takes in InitParams and then uses

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.