Arrays can be one-dimensional, but multidimensional. The members of a number of ancestors can be neat, or can be longer (jagged).
One-dimensional arrays are the most common and simplest. Here the value gives an example, not much explanation. */
Using System;
Class Test
{
static void Main () {
int[] arr = new INT[5];
for (int i = 0; i < arr. Length; i++)
Arr[i] = i * i;
for (int i = 0; i < arr. Length; i++)
Console.WriteLine ("arr[{0}] = {1}", I, arr[i]);
}
}
/* The results are as follows:
Arr[0] = 0
ARR[1] = 1
ARR[2] = 4
ARR[3] = 9
ARR[4] = 16
We can also compare the definition and assignment of multidimensional, regular, variable-length arrays: * *
Class Test
{
static void Main () {
int[] A1 = new int[] {1, 2, 3}; One-dimensional
int[,] a2 = new int[,] {1, 2, 3}, {4, 5, 6}}; Two-dimensional
Int[,,] a3 = new int[10, 20, 30]; Three - dimensional
int[][] J2 = new int[3][]; Become longer
J2[0] = new int[] {1, 2, 3};
J2[1] = new int[] {1, 2, 3, 4, 5, 6};
J2[2] = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9};
}
}
/*
The example above gives an array of various styles. Variable A1, A2, and A3 are rule arrays. The J2 is the variable length array.
An array of rules can easily calculate their length. For example, the length of A3 is: 10*20*30=6000. Instead, it becomes longer
The array is a bit different, and each dimension must be defined separately. If the first dimension of J2 is 3, the second is 6,
Three are 9, so the total length is: 1*3+1*6+1*9=18.
The above arrays are assigned in a rigorous style, and in some cases we can simplify the wording, but I always feel that this simplification
Too many application restrictions, error prone. No introductions are made here. Here's another example of how the arguments in a function
Assigned Value * *
Class Test
{
static void F (long[] arr) {}
static void Main () {
F (New longt[] {1, 2, 3});
}
}
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