Differences between two-dimensional arrays in Java and C #

Source: Internet
Author: User

Using two-dimensional arrays in Java

public class Array2D ... {
public static void Main (string[] args) ... {
int myint[][]=new int[5][10];
Traversal, assigning values to each array of arrays
for (int i=0;i<myint.length;i++) ... {
for (int j=0;j<myint[0].length;j++) ... {
Myint[i][j]=i*j;
}
}
System.out.println ("myint.length=" +myint.length+ ", myint[0].length=" +myint[0].length);
The lower and upper bounds of each dimension of the output array
for (int i=0;i<myint.length;i++) ... {
for (int j=0;j<myint[0].length;j++) ... {
System.out.println ("myint[" +i+ "] [" +j+ "]=" +myint[i][j]);
}
}
}
in C # int[][] MyInt is declaring a jagged array, declaring a two-dimensional array is so declared int[,] myInt, if the above code is replaced by C #, it needs to be represented as follows:

Class CLSARRAT2D
{
/**////<summary>
The main entry point for the application.
</summary>
[STAThread]
static void Main (string[] args)
{
int[,] myint=new int[5,10];
Traversal, assigning values to each array of arrays
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;
}
}
The lower and upper bounds of each dimension of the output array
for (int i=0;i<myint.rank;i++)
{
Console.WriteLine ("{0} {1} {2}", I, Myint.getlowerbound (i), Myint.getupperbound (i));
}
Traversal, outputting 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 ();
}
}

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.