Yes, I have noted what you said too. I believe it is because the
GetEnumerator()
is not a callable thing. It is used from the foreach context as has been
noted. You
don't really call it from the code. Hopefully one of the other folks can
explain the
details of why the method itself isn't callable. I just found an example
that I follow
and have continued on the tradition, so to speak...
"raylopez99" <ra********@yahoo.comwrote in message
news:fd**********************************@y38g2000 hsy.googlegroups.com...
On Sep 20, 4:03 pm, "Family Tree Mike"
<FamilyTreeM...@ThisOldHouse.comwrote:
Change the code to look like this in your foreach within main:
foreach (string s in ((IEnumerable <string>)nlist))
Console.Out.WriteLine(string.Format("The next name is: {0}", s));
foreach (int i in ((IEnumerable<int>)nlist))
Console.Out.WriteLine(string.Format("The next integer is: {0}", i));
Thanks FTM, that worked.
BTW, a minor aside, I notice that you 'repeat' GetEnumerator() ***
(see below) rather than use the 'convention', that I've seen in some
books, of this format (for the non-generic IEnumerator, which is
required):
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
But, when I tried this above 'convention' in your code, I could not
compile it, in fact, IntelliSense would not even recognize
GetEnumerator (!). So I wonder if you've come across this.
However,it's not a big deal since I just use your convention and it
works fine.
Thanks again,
RL
***
System.Collections.IEnumerator
System.Collections.IEnumerable.GetEnumerator()
{
for (int idxLast = 0; idxLast < LastNames.Count(); idxLast
+
+)
//BTW ++idxLast (made globally) also works fine, strangely enough
for (int idxFirst = 0; idxFirst < FirstNames.Count();
idxFirst++)
yield return string.Format("{0} {1}",
FirstNames[idxFirst], lastNames[idxLast]);
for (int i = 0; i < iArrNamer.Length; i++)
{
yield return iArrNamer[i];
}