By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,492 Members | 1,261 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,492 IT Pros & Developers. It's quick & easy.

question about array bounds checking

P: n/a
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.
Nov 16 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Flip" <[remove]ph******@hotmail.com> wrote in message
news:Oj**************@TK2MSFTNGP10.phx.gbl...
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.

Nov 16 '05 #2

P: n/a
Flip <[remove]ph******@hotmail.com> wrote:
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?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3

P: n/a
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. :>
Nov 16 '05 #4

P: n/a
> 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.
Nov 16 '05 #5

P: n/a
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).

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Flip" <[remove]ph******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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. :>

Nov 16 '05 #6

P: n/a
> 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.
Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.