Cycling through a collection in compact framework- Possible?

R

RobGSCL

In vb6, objects were part of a collection and you could cycle through
the collection as follows:

For Each panel in Panels
do something
Next panel

Is there anythin like this for CF?
 
P

Peter Foot [MVP]

Yes, any class which implements IEnumerable (including all arrays) can be
used with a For Each loop.

Peter
 
T

tamberg

Specifically for Panel controls of a Form f an additional typeguard is
necessary. It would result in (C#) code like:

foreach (Control c in f.Controls) {
if (c is Panel) {
Panelh = c as Panel;
// do something with h
}
}

Because not each Control is a Panel, the following code does not work:

foreach (Panel h in f.Controls) {
// do something with h
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top