udana
udana

Reputation: 17

Overloading of GetEnumerator

Can't i overload GetEnumerator () like

IEnumerator<T> IEnumerable<T>.GetEnumerator<T> ( T[] val1,T[] val2)

{

  .... some code

}

Upvotes: 1

Views: 957

Answers (4)

Daniel Ives
Daniel Ives

Reputation: 717

How about an extension method?

i.e.:


public static class IEnumeratorExtensions
{
    public static IEnumerator<T> GetEnumerator<T>(this IEnumerable<T> ie,
        T[] val1, T[] val2)
    {
        //your code here
    }
}

...
string[] s1;
string[] s2;

var qry = from s in new string[]{"1", "2"}
          select s;

qry.GetEnumerator(s1, s2);
...

But what are you trying to do in this "overload"? If you want to merge those two arrays of T, IEnumerable already has a number of methods which take methods. Make sure you're not reinventing the wheel!

Upvotes: 0

Romain Verdier
Romain Verdier

Reputation: 13011

You can propose an overload for GetEnumerator method, but it can't be part of the IEnumerable implementation.

Upvotes: 2

Christian Hayter
Christian Hayter

Reputation: 31071

No. Just create a normal method instead, e.g.

IEnumerator<T> MyCustomEnumerator<T>(T[] val1, T[] val2) {
    // some code
}

Upvotes: 3

Henrik
Henrik

Reputation: 23324

GetEnumerator doesn't take parameters.

Upvotes: 1

Related Questions