Re: Technical two dimensional array question

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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.


.



Relevant Pages

  • Re: Object Array Error
    ... references are set to null. ... To fix this, you ... reference into the array. ... > This throws the exception ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: regex question - trying to find ".mp3" in a SELECT box
    ... But `Array' is a Function object reference. ... Establish a new execution context using F's FormalParameterList, ... Since is not a primitive value, the exception should be thrown. ... | 5.2 Algorithm Conventions ...
    (comp.lang.javascript)
  • Re: An isArray test (and IE bugs)
    ... is not 'Array' must not be an Array, ... You have no choice but to catch every exception that is thrown in a - try - block, but only the exceptions that you expected to be catching should be handled in the - catch - block. ... That suggests that each - catch - block should contain the code to identify the exact type and nature of the exception thrown so that all the exceptions that you did not expect to be catching can be re-thrown. ... So while you could examine the strings in an given set of browsers/browser configurations you are going to hard pressed to be in a position to identify the exception in a browser that you have never seen. ...
    (comp.lang.javascript)
  • Re: Test if memory pointer is valid?
    ... I can see setting a new pointer initially to the address of the beginning of an array, for example, and then incrementing the pointer to address subsequent elements, but that would usually be done inside a function, where the new pointer would go out of scope at the end of the function and be reinitialized if it is called again. ... I would like to see a specific example where it is necessary to have multiple references such as this where it would be necessary to check for it having been freed. ... copies of all the TLabel references already in the form as individual ...
    (comp.lang.pascal.delphi.misc)
  • Re: UBound not in Intellisense. References problem?
    ... but you can produce an array by using Value ... I wouldn't worry about it not appearing in intellisense. ... > I wonder if I have a corruption in my registration of References, ... I get UCase, UCase$, but no UBound. ...
    (microsoft.public.excel.programming)