-
May 11th, 2011, 11:09 AM
#1
Most confusing error I have ever encountered
Hi all.
I am trying to make an app for the .NET framework, and am going well, except that when I tried to implement IEnumerable on a custom object I get the following error:
"Connot implicitly convert type 'System.Collections.Generic.IEnumerator<MyClass>' to 'System.Collections.Generic.IEnumerator<MyClass>'. An explicit conversion exists (are you missing a cast?)"
It might just be me, but that does not make any sense what-so-ever.
Context:
public class MyClass...
public class MyClassCollection
{
private List<MyClass> InnerList;
public IEnumerable<MyClass> GetEnumerator()
{
return ((IEnumerable<MyClass>)this.InnerList).GetEnumerator(); // Line that has error
}
}
-
May 11th, 2011, 03:40 PM
#2
Re: Most confusing error I have ever encountered
Are you sure that what you've posted is in fact the error you've got? Maybe you mistyped something (IEnumerator/IEnumerable)?
Originally Posted by LEGEND383
public class MyClass...
public class MyClassCollection
{
private List<MyClass> InnerList;
public IEnumerable<MyClass> GetEnumerator()
{
return ((IEnumerable<MyClass>)this.InnerList).GetEnumerator(); // Line that has error
}
}
Why does your GetEnumerator() method return an IEnumerable?
Fix all that, and the error should be gone. Also, I think that you can return an enumerator by just calling this.InnerList.GetEnumerator().
P.S. Please use the [code][/code] tags when posting code - it will preserve formatting.
Last edited by TheGreatCthulhu; May 11th, 2011 at 03:43 PM.
-
May 11th, 2011, 04:22 PM
#3
Re: Most confusing error I have ever encountered
Yes, and you also don't need the cast anyway. Just return InnerList.GetEnumerator()
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|