A simple analysis of C # defining an integral type array

Source: Internet
Author: User
The array in C # is a reference type, and C # defines an integer array as follows:

int [] Intarray = {A-i}; or int [] Intarray = new INT[10];

The way to define an integer array in C + + is:

int intarray[] = {n/a}; or int * Intarray = new INT[10];

C # defines an integral array that can be one-dimensional or multidimensional, and also support matrices and jagged arrays.

Note: The way to define a multidimensional array (matrix) is [,] and the way to define multidimensional "jagged matrices" is []. In addition, the use of the new keyword does not necessarily mean that the object is dynamically allocated (into the stack).

Here is a common definition of a (one-dimensional) multidimensional array in C #:


  
int []A1; Defining a one-dimensional array
int [,]A2; Defining a two-dimensional array
int [,,]a3; Defining three-dimensional arrays
int []A1 = new int [10]; Defining a one-dimensional array depth
int [,]A2 = new int [10,20]; Defining two-dimensional array depth
int [,,]a3 = new int [10,20,30]; Defining three-bit array depth
int []A1 = new int []{1,2,3}; Initialization
int [,]A2 = new int [,]{{1,2,3},{4,5,6}};

You can also define an array of "jagged":


  
int [][]var = new int [3][];
Var[0] = new int[]{1,2,3};
VAR[1] = new int[]{1,2,3,4,5,6};
VAR[2] = new int[]{1,2,3,4,5,6,7,8,9};

Note that the difference between int [,]a, and int [][]a: The former defines a two-dimensional fixed array, which defines a two-dimensional mutable array. Only they have not yet been allocated space and initialized. int [][]var = new int[3][4]; it's wrong.

The following error:


  
Class Test
{
static void F (int []arr) {}
static void Main ()
{
F ({A-i});//Error! {A-i} is not a valid expression.
}
}
  
Class Test
{
STATCI void F (int []arr) {}
static void Main ()
{
F (new int []{1,2,3});
}
}

The above describes C # defining an integral array


Related Article

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.