c# - GetEnumerator: return or yield return -


my class implements ienumerable. , these 2 ways code getenumerator method can compiled:

public ienumerator getenumerator() {     yield return database[id].getenumerator(); } 

and

public ienumerator getenumerator() {    return database[databaseid].getenumerator(); } 

where database[id] list. difference between these implementations?

the reason compiles because being unclear enumerable is. if make generic becomes more obvious:

public ienumerator<foo> getenumerator() {     return database[id].getenumerator(); } 

vs

public ienumerator<ienumerator<foo>> getenumerator() {     yield return database[id].getenumerator(); } 

your yield return version not yielding result: yielding the iterator - iterator-of-iterators, enumerator-of-enumerators. , not in way. basically, "don't that".


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -