Question

Can't i overload GetEnumerator () like

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

{

  .... some code

}
Was it helpful?

Solution

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

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

OTHER TIPS

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

GetEnumerator doesn't take parameters.

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top