Virtual GetEnumerator?

This is a discussion on Virtual GetEnumerator? within the C# Programming forums, part of the General Programming Boards category; When designing collection classes, should GetEnumerator be virtual if it implements the generic IEnumerable interface? I can't think of a ...

  1. #1
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399

    Virtual GetEnumerator?

    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.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  2. #2
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Virtual Box
    By ssharish2005 in forum Tech Board
    Replies: 3
    Last Post: 02-12-2009, 05:08 AM
  2. Replies: 48
    Last Post: 09-26-2008, 04:45 AM
  3. Program with Shapes using Virtual Functions
    By goron350 in forum C++ Programming
    Replies: 12
    Last Post: 07-17-2005, 02:42 PM
  4. C++ XML Class
    By edwardtisdale in forum C++ Programming
    Replies: 0
    Last Post: 12-10-2001, 11:14 PM
  5. Exporting Object Hierarchies from a DLL
    By andy668 in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 02:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21