This is a bit weird. I'm working with a windows application using C#. I'm developing in Visual Studio.NET 2005. I'm using the card.dll that comes with all PC's just so you know. Each card that I'm using is a control. I want to go through all the controls and if it's a card I remove it. I have a loop:
foreach(Control ctr in this.Controls)
{
//do code
}
When I get a count of all the controls (this.Controls. Count) I get 72. But in my foreach loop it's only going through 46 times.
I tried changing it to a for loop
intMyControlCou nt = this.Controls.C ount;
for(int x = 0; x < intMyControlCou nt; x++)
{
//do code
}
but after it gets past 46 i get an index out of range error. This doesn't make sense to me. The count is returning 72.
If I run that foreach loop like 4 times then it eventually goes through all of them haha. But not good obviously. Can anyone help please?
foreach(Control ctr in this.Controls)
{
//do code
}
When I get a count of all the controls (this.Controls. Count) I get 72. But in my foreach loop it's only going through 46 times.
I tried changing it to a for loop
intMyControlCou nt = this.Controls.C ount;
for(int x = 0; x < intMyControlCou nt; x++)
{
//do code
}
but after it gets past 46 i get an index out of range error. This doesn't make sense to me. The count is returning 72.
If I run that foreach loop like 4 times then it eventually goes through all of them haha. But not good obviously. Can anyone help please?