When designing collection classes, should GetEnumerator be virtual if it implements the generic IEnumerable interface? I can't think of a single good reason why it should be. On the other hand, I can't think of a single bad reason either.
Printable View
When designing collection classes, should GetEnumerator be virtual if it implements the generic IEnumerable interface? I can't think of a single good reason why it should be. On the other hand, I can't think of a single bad reason either.
I love to make methods virtual. The reason is one day, you might decide to create another class inheriting from the one you just made. And you might just decide you need to override GetEnumerator. If you do, you'll find yourself cursing at the complete moron who decided not to make it virtual :)
That said, I do believe there is a very slight performance hit when it comes to calling virtual methods.
See here:
http://www.paulstovell.net/Posts/Pos...5-701d3d25eff6