Avatar of BlearyEye
BlearyEye
Flag for United States of America asked on

Copying OpenForms to array

This should be Really Simple but ... I'm using C# 4.0. I want to copy Application.OpenForms to an array without writing my own loop.

Application.OpenForms is of type System.Windows.Forms.FormCollection. This type does not have a CopyTo method, but http://msdn.microsoft.com/en-us/library/system.windows.forms.formcollection.aspx says that ICollection.CopyTo is an explicit interface implementation. I don't see how to go about using that.
C#.NET Programming

Avatar of undefined
Last Comment
BlearyEye

8/22/2022 - Mon
Jacques Bourgeois (James Burger)

You cannot use the CopyTo mentionned in that web page.

If you look carefully, there is not hyperlink from the ICollection.CopyTo method. Only an indication that it is inherited from ReadOnlyCollectionBase. If you follow that lead, you see that the method is Private. That means that is it only used internally by ReadOnlyCollectionBase and cannot be used. When you see a list of methods under a heading of Explicit Interface Implementations, it is an indication for programmers who would want to inherit from the class, not things that you can use from an instance of the class.

Since Microsoft has not built a Copy method into the class, you have no choice, you need to loop. What is wrong with that? It requires only 3 lines of code.
ASKER CERTIFIED SOLUTION
Meir Rivkin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
BlearyEye

ASKER
Looks good, thanks.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23