.


:




:

































 

 

 

 


Array




: , , dataGridView.

 

3.1. #

. . , . . C#, , . , , , , , .

, 0-, , C# . .. .

 

:

<>[] <>;

C++ , . , T[] , T.

, . . , , , . , .

:

[] ;

[] = new [ ];

[] = { _ };

[] = new [] { _ };

[] = new [ ] { _ };

:

int[] a; // 1

int[] b = new int[4]; // 2 0

int[] c = { 61, 2, 5, -9 }; // 3 new

int[] d = new int[] { 61, 2, 5, -9 }; // 4

,

int[] e = new int[4] { 61, 2, 5, -9 }; // 5

, , . , .

. , , . - . C# , C# .

, :

static void TestDynAr() {

// A1

Console.WriteLine(" A1");

int size = int.Parse(Console.ReadLine());

int[] A1 = new int[size];

Arrs.CreateOneDimAr(A1);

Arrs.PrintAr1("A1",A1);

}

.

 

, - . , , - , , .

. . :

<>[, ,] <>;

, , . , , , . , , - . , :

int[,]matrix = {

{1,2},

{3,4}

};

. :

[,] ;

[,] = new [ _1, _2 ];

[,] = { _ };

[,] = new [,] { _ };

[,] = new [ _1, _2 ] { _ };

( ):

int[,] a; // 1

int[,] b = new int[2, 3]; // 2 0

int[,] c = {{1, 2, 3}, {4, 5, 6}}; // 3 new

int[,] c = new int[,] {{1, 2, 3}, {4, 5, 6}}; // 4 ,

int[,] d = new int[2,3] {{1, 2, 3}, {4, 5, 6}};// 5

, , , :

a[1, 4];

b[i, j];

b[j, i];

 

C# , (jagged arrays). , , , , . , . , , . - Fathers, , , Fathers[i] - i- . - Children, Children[i] - i- , Children[i][j] - j- i- . , GrandChildren [i][j][k] - j- i- .

. , - ; , int[][] , - int.

. new int[3][5], . . .

 

// -

//

int[][] jagger = new int[3][] {

new int[] {5,7,9,11},

new int[] {2,8},

new int[] {6,12,4}

};

jagger . , , . new, . , .

 

foreach

foreach . . , : . :

foreach ( in ) _

, ( ). , , . . , :

int[] a = { 24, 50, 18, 3, 16, -7, 9, -1 };

foreach :

foreach (int x in a) Console.WriteLine(x);

: , .

 

Array

Array. :

Length ( )
BinarySearch
Clear
Copy
GetValue
IndexOf
Reverse
Sort

3.1.7. :

//

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

// (- )

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

// ,

string[,] array2Db = new string[3, 2] { { "one", "two" }, { "three", "four" },

{ "five", "six" } };

 

//

int[,,] array3D = new int[,,] { { { 1, 2, 3 }, { 4, 5, 6 } },

{ { 7, 8, 9 }, { 10, 11, 12 } } };

//

int[,,] array3Da = new int[2, 2, 3] { { { 1, 2, 3 }, { 4, 5, 6 } },

{ { 7, 8, 9 }, { 10, 11, 12 } } };

 

//

System.Console.WriteLine(array2D[0, 0]);

System.Console.WriteLine(array2D[0, 1]);

System.Console.WriteLine(array2D[1, 0]);

System.Console.WriteLine(array2D[1, 1]);

System.Console.WriteLine(array2D[3, 0]);

System.Console.WriteLine(array2Db[1, 0]);

System.Console.WriteLine(array3Da[1, 0, 1]);

System.Console.WriteLine(array3D[1, 1, 2]);

 

// ( ):

// 1

// 2

// 3

// 4

// 7

// three

// 8

// 12

 





:


: 2017-04-15; !; : 1180 |


:

:

- , 20 40 . - .
==> ...

1632 - | 1590 -


© 2015-2024 lektsii.org - -

: 0.021 .