5.9 Two-dimensional arrays

Source: Internet
Author: User

Two-dimensional arrays

    1. Defining a two-dimensional array

Int [,]myarray =new int[ Several one-dimensional arrays, number of arrays ];

An array can have more than one dimension. For example, the following declaration creates a two-dimensional array of four rows and two columns (which can be understood as 4 1 -dimensional arrays, with 2 elements in the array ):

Int [,] myarray=new int[4,2];

Int [,] myarray=new int[4,2] {{1,2},{3,4},{5,6},{7,8}};

The value is

Int i= myarray[0,0]

The output result I is:1

Int i=myarray[0,1]

The output result I is:2

Multidimensional arrays

An array can have more than one dimension. For example:

Int[,,] myArray = new int [2,4,2]

{{1,2},{3,4},{5,6},{7,8}}

{{9,10},{11,12},{13,14},{15,16}};

Enter class size, create an array based on the number of people

Storage language, math, English score

Ask for the average score for everyone

Console.Write (" Please enter class number:");

int a = Int. Parse (Console.ReadLine ());

double[,] Fenshu = new double[a, 3];

for (int i = 0; i < A; i++)

//{

Console.Write (" Please enter " + (i + 1) + " personal language score:");

Fenshu[i, 0] = double. Parse (Console.ReadLine ());

Console.Write (" Please enter " + (i + 1) + " personal math score:");

Fenshu[i, 1] = double. Parse (Console.ReadLine ());

Console.Write (" Please enter " + (i + 1) + " personal English score:");

Fenshu[i, 2] = double. Parse (Console.ReadLine ());

//}

for (int i = 0; i < A; i++)

//{

Double sum = fenshu[i, 0] + fenshu[i, 1] + fenshu[i, 2];

Console.WriteLine (" the" + (i+1) + " the average score of the individual is:" +SUM/3);

//}

Console.ReadLine ();

Five candidate Monitor, a vote. (Enter 1-5 to indicate which person to support)

Finally check the number of votes to see which one wins

int[] Piao = new INT[20];

            //console.writeline (" Span style= "font-family: Microsoft Jacob Black;" > Vote for squad leader, enter 1~5 which one is supported!

Console.WriteLine ("1: Zhang San 2: John Doe 3: Harry 4: Zhao Liu 5: Feng qi ");

for (int i = 0; i < 20;i++)

//{

Console.Write (" please " + (i+1) + " individual to vote:");

Piao[i] = Int. Parse (Console.ReadLine ());

//}

int fei = 0;

Int[] Shu = new int[] {0, 0, 0, 0, 0};

for (int i = 0; i <; i++)

//{

Switch (Piao[i])

//    {

Case 1:

shu[0]++;

Break

Case 2:

shu[1]++;

Break

Case 3:

shu[2]++;

Break

Case 4:

shu[3]++;

Break

Case 5:

shu[4]++;

Break

Default

fei++;

Break

//    }

//}

5.9 Two-dimensional arrays

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.