.


:




:

































 

 

 

 


Length




 

# , . Length. Length, ( ( ) , ).

 

int[] sample = new int [10];

int val = sample.Length;

foreach

 

# foreach, . . C# , .

foreach , , , , ..

:

 

foreach (type var_name in collection)

{

statements;

}

 

typevar_name , foreach. collection.

- . , . , (, ) . , , , . - , . , .

foreach C# , , . .

foreach .

 

int k;

int[] mas = new int[5];

for(k=0; k < 5; k ++) mas[k]=k;

sum = 0;

foreach(int i in mas)

{

Console.Write(" = " + i);

sum += i;

}

, foreach .

foreach . .

foreach , , .

 

List

 

List . List , , . . , . , .

.

 

List<type> name = new List<type>();

type . . name.

. ..

:

 

Add([])
AddRange([ ])
Insert([],[]) ,
InsertRange([], [ ]) ,

 

List<string> dinosaurs = new List<string>();

dinosaurs.Add("Tyrannosaurus");

dinosaurs.Add("Amargasaurus");

dinosaurs.Add("Mamenchisaurus");

 

Remove([])
RemoveRange([], []) ,
RemoveAt([]) ,
Clear()

 

Count Length .

Contains , .

 

foreach. Car. .

 

List<Car> cars = new List<Car>();

foreach (Car car in cars)

{





:


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


:

:

,
==> ...

1516 - | 1389 -


© 2015-2024 lektsii.org - -

: 0.008 .