How could it ever be that the following code should result in an IndexOutOfRange exception? I ask because that's what's happening.
[HIGHLIGHT="C#"]
number = such and such;
if(number > 9)
{
string blah = number.ToString();
byte whatever = byte.Parse(blah [ (blah.Length - 1) ] + "");
}
[/HIGHLIGHT]
I have even tried 'byte.Parse(blah[0] + "");' and even that causes an IdexOutOfRange exception to be thrown. I have tried breaking at the point of failure and analyzing the various relevant variable values and they all check out; Blah.Length = 3 and Blah = "422" when it fails.
Is this an example of heap corruption or some such? How should I go about fixing this?
I thank you for your time.
Baffling failure
Started by shikaningen, Nov 02 2007 09:09 PM
2 replies to this topic
#1
Posted 02 November 2007 - 09:09 PM
|
|
|
#2
Guest_Kaabi_*
Posted 09 November 2007 - 12:26 PM
Guest_Kaabi_*
I would be interested to see what is wrong with this code, as it looks fine.
#3
Posted 22 December 2007 - 09:23 PM
That's messed up. Maybe you've got some bad memory or something. Your code looks fine, and I typed it into a test program using the value 422 myself. Did you ever find out what was going on?


Sign In
Create Account

Back to top









