A two-dimensional array of C # languages

Source: Internet
Author: User

content :

two-dimensional arrays :
One-dimensional array---beans
Two-dimensional array---table

Defined:
One-dimensional arrays:
data type [] array variable name = new data type [array length];
data type [] array variable name = new data type [array length]{1,2,3 ...};

Two-dimensional arrays:
data type [,] array variable name = new data type [number of rows, number of columns];
int[,] a = new int[3,4];

Assignment value:
a[row subscript, column subscript] = value subscript is starting from 0
Value:
a[row subscript, column subscript]

jagged data, an array of arrays .
Defined:
First step: Define a large Array
data type [] A = new data type [number of rows] [];
Step two: Define the decimal group
Data type [] a1 = new data type [number of columns];
Data type [] a2 = new data type [number of columns];
......
Step three: Put the decimal group in a large array
A[0] = A1;
A[1] = A2;
....

*int[,] a = new int [3][4]; Wrong
*int[][] A = new int[3,4];//error
*int[][] A = new int[3][4];//error
*int[,] C = new int[3,4];//pair

* *always note the format of writing distinguishes between two-dimensional arrays and jagged arrays (arrays of arrays).

Cases:

Int[][] A = new int[3][];

int[] A1 = new int[] {3, 4, 5, 6, 7};
int[] A2 = new int[] {1, 2, 3};
int[] a3 = new int[] {7, 8, 9, 10};

A[0] = A1;
A[1] = A2;
A[2] = A3;
A[0] Represents the first (int[3]) in int[][]a=newint[3][]

others, etc.


Collection:

One, ArrayList linked list, there is no length limit, you can add or remove elements at any time.
Need to be preceded by: using System.Collections;

Defined:
ArrayList a = new ArrayList ();
Operation:
A.add (data): add
A.insert (index number, data): Insert
A.removeat (index number): delete
A.count the number of elements in the collection

Value:
a[Subscript]
The value taken out needs to be cast.

Second, list< type > Linked list, there is no length limit, you can add or remove elements at any time. Only data of the specified type can be placed, and no casts are taken out.
Defined
list< type > variable name = new list< type > ();
List<int> a = new list<int> ();
Operation:
A.add (data): add
A.insert (index number, data): Insert
A.removeat (index number): delete
A.count the number of elements in the collection

A.sort (); sort
A.reverse (); reverse

Take value
a[index number]

Third, dictionary<key,value> dictionary or hash table
Defined
Dictionary<int,string> a = new dictionary<int,string> ();

Operation:
A.add (key value, data);
A.remove (key value);
A.count;

Value:
a[Key value]


Four, stack, the queue know it's OK
Stack: Advanced after, can not randomly take any one of the values.
stack< data type > A = new stack< data type > ();
A.push (value);
Data type variable name = A.pop ();

Team Example: FIFO, can not randomly take any one of the values.
Queue<int> a = new queue<int> ();
A.enqueue (value);
Data type variable = A.dequeue ();

A two-dimensional array of C # languages

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.