Question : How to implement getenumerator() method in a genrics class

Hi,

 I have a class the code for which is as follow

public class SafetyEnumerable<T> : IEnumerable<T>, IEnumerable
    {
        // Fields
        private readonly IEnumerable collection;

        // Methods
        public SafetyEnumerable(IEnumerable collection)
        {
            this.collection = collection;
        }

        public IEnumerator GetEnumerator()
        {
            return ((IEnumerable<T>)this).GetEnumerator();
        }

        IEnumerator<T> IEnumerable<T>.GetEnumerator()
        {
            //How to implement this Enumerator
        }
    }

   As there are two interfaces we need to implement all the interface method,, hence the last method  IEnumerator<T> IENumerable<T>.GetEnumerator() is my problem. I want to implement this method so that this method works.

Please advice

Thanks and
Warm Regards
Pradip

Answer : How to implement getenumerator() method in a genrics class


A small correction in my above code (need to specify <T> for the collection field):
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
public class SafetyEnumerable<T> : IEnumerable<T>
    {
        // Fields
        private readonly IEnumerable<T> collection;

        // Methods
        public SafetyEnumerable(IEnumerable<T> collection)
        {
            this.collection = collection;
        }

        IEnumerator<T> IEnumerable<T>.GetEnumerator()
        {
            return collection.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return collection.GetEnumerator();
        }
    }
Random Solutions  
 
programming4us programming4us