views:

118

answers:

4

Can't i overload GetEnumerator () like

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

{

  .... some code

}
+1  A: 

GetEnumerator doesn't take parameters.

Henrik
+3  A: 

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

IEnumerator<T> MyCustomEnumerator<T>(T[] val1, T[] val2) {
    // some code
}
Christian Hayter
Thanks done what you said.
udana
+2  A: 

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

Romain Verdier
Thanks Romain Verdier
udana
A: 

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!

Daniel Ives