question about array bounds checking

  • Thread starter Thread starter Flip
  • Start date Start date
F

Flip

I'm reading the O'Reilly's Progamming C# book and I have a question about
array bounds checking. On page 174, near the top, they show an example
where c# does indeed to array bounds checking cause the example shows a
System.IndexOutOfRangeException being thrown. However, in the very next
section (Jagged arrays) they have warning section that says "Java
programmers take note: While Java does bounds checking on array use, C# does
not." Huh? I hope you can see my confusion, in one case, it's clear C#
does cause it's throwing an exception, but yet at the bottom of the page it
says C# doesn't do it. Which is right?

Thanks.
 
Flip,

I would think that the second section is incorrect. I don't have the
book, so I don't know exactly what it says, but .NET definitely does
checking on array bounds (however, it can be shut off, perhaps there is a
comment about that somewhere in the book).

Hope this helps.
 
Flip said:
I'm reading the O'Reilly's Progamming C# book and I have a question about
array bounds checking. On page 174, near the top, they show an example
where c# does indeed to array bounds checking cause the example shows a
System.IndexOutOfRangeException being thrown. However, in the very next
section (Jagged arrays) they have warning section that says "Java
programmers take note: While Java does bounds checking on array use, C# does
not." Huh? I hope you can see my confusion, in one case, it's clear C#
does cause it's throwing an exception, but yet at the bottom of the page it
says C# doesn't do it. Which is right?

That sounds very wrong. I don't have the book myself - could you post
the entire paragraph?
 
I just got a reply back from the author and I was pointed to the errata
webpage where it says.

"Page 174 [2/16/04]
Note at bottom of page (Java Programmers take note...) Please remove this
note as it is incorrect; C# does provide bounds checking for arrays."

So C# does indeed to bounds checking on our behalf. :>
 
That sounds very wrong. I don't have the book myself - could you post
the entire paragraph?
Thanks for the reply, however I don't believe that will be necessary (type
paragraph out I mean). I found out c# does indeed do bounds checking and it
was part of the errata section on the author's website.

Thanks again.
 
Flip,

It should be important to note that it is not C# that does this (it is
just a language) but rather, the .NET runtime that does this for you (the
bounds checking).
 
It should be important to note that it is not C# that does this (it is
just a language) but rather, the .NET runtime that does this for you (the
bounds checking).
True! I guess this is a bit of java-bias I still have to work out of my
system! :> In know, I know, in java, it's much the samething (java =
language) and it's the jvm that does this. But you can't run java without
the jvm, so easier to think of those two as one and the same. Not entirely
accurate, but helps a newbie learn things. :>

Thank again for your clarifications.
 
Back
Top