Index out of bound error when I know its not
I am trying to run this loop
Code:
int y = 0;
char[] tempmess = new char[] { };
for (int a = 56; a < SMS.Length; a++ )
{
tempmess[y] = SMS[a];
y++;
}
and I keep getting an index out of bounds exception when I know its not. SMS which is a char array has a length of 76. if I manually put in the number it works but if I try and loop it crashes long before it hits the end.
EDIT: its an IndexOutOfRange Exception
Re: Index out of bound error when I know its not
Which line is highlighted wit the error?
Re: Index out of bound error when I know its not
What is the value of a and y when this happens?
-tg
Re: Index out of bound error when I know its not
Hmm, perhaps if tempmess[] was defined to have more than 0 elements... :rolleyes:
Re: Index out of bound error when I know its not
Couldn't you use something like this?
Code:
char[] subSMS = SMS.ToString().Substring(56).ToCharArray();
I know that's probably really bad coding and perhaps inefficient but I'm kind of new with this sort of thing.:)