Why do you do it manually? yield return
automates the entire process of handling iterators. (I also wrote about it on my blog, including a look at the compiler generated code).
If you really want to do it yourself, you have to return a generic enumerator too. You won't be able to use an ArrayList
any more since that's non-generic. Change it to a List<MyObject>
instead. That of course assumes that you only have objects of type MyObject
(or derived types) in your collection.