Re: Technical two dimensional array question
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Mon, 2 Jan 2006 16:01:43 +0100
inline
Willy.
"Jesika" <Jesika@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:4D2D733B-1B8F-4A3E-8FB1-DA421FBA060E@xxxxxxxxxxxxxxxx
> Hi, I have a cumbersome question:
>
> Given the following declaration:
>
> string [,] varray = new string[3,5]; (15 blocks of memory)
>
> Does it allocate a contiguous blocks of memory or not? If it does,
> is it guaranteed to be contiguous everytime?
>
Yes, the array of "string references" is guaranteed to be contigious.
> What If I tried to go out of range but in a knowingly safe manner like the
> following in order to assign to the next array out of the 3 arrays:
>
> varray[0,5] = "string object"; // out of range overflow
> console.writeline(varray[0,1]);
>
> I tried it and I get an exception error, as I should, but, I also tried
> catching the exception to allow it to work but the problem is that the
> exception blocked my program before the assignment could occur; proving
> why I
> said it did not work. Am I wrong on this last assumption?
>
You can catch (and swallow) the exception, but you can never assign a
reference to a location that is outside of the array bounds. Why would you
ever wanna do this?
> In C, something like this particular program would work becuase C is not
> very strict when it comes to safety conforms.
>
No, such program contains a bug, it can seeingly work, but sooner or later
it will fail as you are overwriting whatever is located after the last array
element.
> I would appreciate if someone could answer these two questions for me, and
> also, if I could be refered to a book that gets into the nity-gritty
> technicalities of C# semantics. Especially concerning with the subject of
> this thread.
>
> Thanks in advance,
> Jesika.
.
- Prev by Date: Table, Row and Cell problem
- Next by Date: Re: Table, Row and Cell problem
- Previous by thread: Re: Technical two dimensional array question
- Next by thread: Table, Row and Cell problem
- Index(es):
Relevant Pages
|