Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does TreeNodeCollection not implenent IEnumerable<TreeNode>?

Tags:

.net

winforms

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?

like image 866
Sean Kearon Avatar asked Sep 01 '08 08:09

Sean Kearon


1 Answers

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.Linq; 
... 
var nodes = GetTreeNodeCollection().OfType<TreeNode>();
like image 90
Artem Tikhomirov Avatar answered Oct 15 '22 03:10

Artem Tikhomirov