arrays
torhu
no at spam.invalid
Mon Jan 28 22:15:28 PST 2008
tytower wrote:
> [code]
> this() {
> char[][] data ;
>
> char[] dataNumber = "1";
> char[] date = "10/12/08" ;
> char[] m_details = "test";
> char[] m_code = "340" ;
>
> char[] m_debit = "3480.00";
> char[] m_credit;
>
> data[0]= dataNumber;
> data[1]= date ;
> data[2]= m_details;
> data[3][ m_code;
> data[4]= m_debit;
> data[5][ m_credit;
> [/code]
> Compiles OK but gives error
> [code]
> "tango.core.Exception.ArrayBoundsException at transaction(56): Array index out of bounds"[/code]
>
'char[][] data;' doesn't allocate anything but an array reference. So
it's just an empty array to begin with. If you print its length, you'll
see that it's '0'.
Use the append operator instead:
data ~= dataNumber;
data ~= data;
etc.
More information about the Digitalmars-d-learn
mailing list