c# - Making a class foreach-compatible -


this question has answer here:

i have class wraps list of objects. class compatible foreach loop.

i have seen several questions how on so, of answers not compile me.

class tracklist {     private list<track> tracks = new list<track>(); } 

what add make usable each ?

so far have :

class tracklist : ienumerable<track> {     // ...      public ienumerator<track> getenumerator()     {         return tracklist.getenumerator();     }      system.collections.ienumerator system.collections.ienumerator.getenumerator()     {         return this.getenumerator();     } } 

but says (translated error) :

error 1 'hp.tracklist' not implement interface member 'system.collections.ienumerable.getenumerator()'. 'hp.tracklist.getenumerator()' cannot implement 'system.collections.ienumerable.getenumerator()', because doesn't have return type corresponding 'system.collections.ienumerator'. xxx\tracklist.cs 11

if instead use :

ienumerator<track> ienumerator<track>.getenumerator() {     return this.getenumerator(); } 

is giving me same error.

this line wrong:

system.collections.ienumerator system.collections.ienumerator.getenumerator() 

you have 2 types here:

system.collections.ienumerator system.collections.ienumerator.getenumerator() ^----------------------------^ ^----------------------------^   type you're returning       interface you're                                       implementing 

the second should ienumerable not ienumerator make it:

system.collections.ienumerator system.collections.ienumerable.getenumerator() 

also note private field:

private list<track> tracks = new list<track>(); 

is named tracks , not tracklist, i'm assuming typo, otherwise need fix well.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -