Ha! I get it....
I am actually using an adaptation of this technique in production code.
But the adapted code required a dept-first
search and this original pattern is width-first
.
Which brings us these new and improved versions:
public static List<control> FindControlsWidthFirst( Control controlTop )
{
List<control> list = new List<control>();
list.Add(controlTop);
for (int i = 0; i < list.Count; ++i)
{
list.AddRange(list[i].Controls);
}
return list;
}
public static List<control> FindControlsDepthFirst( Control controlTop )
{
List<control> list = new List<control>();
list.Add(controlTop);
for (int i = 0; i < list.Count; ++i)
{
list.InsertRange(i + 1, list[i].Controls);
}
return list;
}
</control></control></control></control>
Doing that 'computer thing' ever since the C64.
Sometimes I feel that being a programmer is much like being a doctor: You just have to know everything and if you don't, something dies.
Either being an application or a patient.
Oddly enough, more people care about the death of their application, than the massacre of people...