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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:10:43+00:00 2026-05-24T10:10:43+00:00

my Code is : using System; using System.Threading; using System.Collections; using System.Collections.Generic; namespace IEnumerable

  • 0

my Code is :

using System;
using System.Threading;
using System.Collections;
using System.Collections.Generic;

namespace IEnumerable
{
    public class MyEnumerable<T> : IEnumerable<T>
    {
        public MyEnumerable(T[] items)
        {
            this.items = items;
        }

        public IEnumerator<T> GetEnumerator()
        {
            return new NestedEnumerator(this);
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        // The enumerator definition.
        class NestedEnumerator : IEnumerator<T>
        {
            public NestedEnumerator(MyEnumerable<T> coll)
            {
                Monitor.Enter(coll.items.SyncRoot);
                this.index = -1;
                this.coll = coll;
            }

            public T Current
            {
                get { return current; }
            }

            object IEnumerator.Current
            {
                get { return Current; }
            }

            public bool MoveNext()
            {
                if (++index >= coll.items.Length)
                {
                    return false;
                }
                else
                {
                    current = coll.items[index];
                    return true;
                }
            }

            public void Reset()
            {
                current = default(T);
                index = 0;
            }

            public void Dispose()
            {
                try
                {
                    current = default(T);
                    index = coll.items.Length;
                }
                finally
                {
                    Monitor.Exit(coll.items.SyncRoot);
                }
            }

            private MyEnumerable<T> coll;
            private T current;
            private int index;
        }

        private T[] items;
    }

    public class EntryPoint
    {
        static void Main()
        {
            MyEnumerable<int> integers = new MyEnumerable<int>(new int[] { 1, 2, 3, 4 });

            foreach (int n in integers)
            {
                Console.WriteLine(n);
            }
        }
    }
}

I am implementing this piece of code But i get an error. Can anybody help me what to do to error free this code? please help.
My Errors are :

1->’IEnumerable’ is a ‘namespace’ but is used like a ‘type’

2->’IEnumerable.MyEnumerable’ does not implement interface member ‘System.Collections.IEnumerable.GetEnumerator()’. ‘IEnumerable.MyEnumerable.GetEnumerator()’ cannot implement ‘System.Collections.IEnumerable.GetEnumerator()’ because it does not have the matching return type of ‘System.Collections.IEnumerator’.

  • 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-24T10:10:45+00:00Added an answer on May 24, 2026 at 10:10 am

    The error is likely that you’re using IEnumerable as your namespace when it’s already a type in the system.

    This means that your references to IEnumerable are refering to the current namespace and not the IEnumerable you’re meaning to use (System.Collections.IEnumerable).

    Try changing your namespace to something else.

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

Sidebar

Related Questions

using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Threading; namespace ClassLibrary { public
This is my code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading;
The following code using System.Threading; class Test { volatile int counter = 0; public
The winform: The code: using System; using System.Windows.Forms; namespace DemoApp { public partial class
This C#/WPF code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using
I have an asynchronous socket listener class like this: using System; using System.Collections.Generic; using
Consider this code... using System.Threading; //... Timer someWork = new Timer( delegate(object state) {
I have the following code: using System; using System.Linq; using System.Linq.Expressions; public class Program
Consider the following code: using System; namespace ConsoleApplication2 { class Program { static void
I get an error when I compile this code: using System; public struct Vector2

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.