Differences between two-dimensional arrays in Java and C #

Source: Internet
Author: User

Using a two-dimensional array in Java

Public class array2d ...{
Public static void main (string [] ARGs )...{
Int Myint [] [] = new int [5] [10];
// Traverse and assign values to each array
For (INT I = 0; I
For (Int J = 0; j
Myint [I] [J] = I * J;
}
}
System. Out. println ("Myint. Length =" + Myint. Length + ", Myint [0]. Length =" + Myint [0]. Length );
// Lower limit and upper limit of each dimension of the output Array
For (INT I = 0; I
For (Int J = 0; j
System. Out. println ("Myint [" + I + "] [" + J + "] =" + Myint [I] [J]);
}
}
}
}

In C #, int [] [] Myint declares an interleaved array, and declares that the two-dimensional array declares int [,] Myint. If the above Code is changed to C, it must be represented as follows:

Class clsarrat2d
{
/**////

/// Main entry point of the application.
///

[Stathread]
Static void main (string [] ARGs)
{
Int [,] Myint = new int [5, 10];
// Traverse and assign values to each array
For (INT I = Myint. getlowerbound (0); I <= Myint. getupperbound (0); I ++)

{
For (Int J = Myint. getlowerbound (1); j <= Myint. getupperbound (1); j ++)
{
Myint [I, j] = I * J;
}
}
// Lower limit and upper limit of each dimension of the output Array
For (INT I = 0; I
{
Console. writeline ("{0} {1} {2}", I, Myint. getlowerbound (I), Myint. getupperbound (I ));
}
// Traverse to output the number of each element in a two-dimensional array
For (INT I = Myint. getlowerbound (0); I <= Myint. getupperbound (0); I ++)
{
For (Int J = Myint. getlowerbound (1); j <= Myint. getupperbound (1); j ++)
{
Console. writeline ("Myint [{0}, {1}] = {2}", I, j, Myint [I, j]);
}
}
Console. Readline ();
}
}

Add to Vivi
Previous Article: Java Abstract class and interface humanized understanding
Next article: differences between the two exceptions in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.