Thursday, January 27, 2011

Why does TreeNodeCollection not implenent IEnumerable<TreeNode>?

TreeNodeCollection, like some of the other control collections in System.Windows.Forms, implements IEnumerable. Is there any design reason behind this or is it just a hangover from the days before generics?

  • Yes, Windows Forms dates back to before generics in .Net

  • Yes, there are many .NET Framework collection, that does not implement generic IEnumerable.

    I think that's because after 2.0 there was no (at least not so match) development of the core part of FW.

    Meanwhile I suggest you to make use of following workaround:

    using System.Link; 
    ... 
    var nodes = GetTreeNodeCollection().OfType<TreeNode>();
    

0 comments:

Post a Comment