|
Elementnishartbo‘yichatopish: using System
|
bet | 8/16 | Sana | 18.05.2024 | Hajmi | 141,69 Kb. | | #241912 |
Bog'liq Latofat777 Elementnishartbo‘yichatopish: using System;
classArrayErr
{
staticvoid Main()
{
varpeople=newstring[]{"Ali","Vali","Abbos","Nodir","Salohiddin","Oybek", "Bekmurod"};
//satruzunligi4tabelgidankattabo‘lganbirinchivaoxirgielementlarnitopish string first = Array.Find(people, rr => rr.Length >4);
Console.WriteLine(first);// Abbos
stringlast=Array.FindLast(people,rr=>rr.Length>4); Console.WriteLine(last); // Bekmurod
//satruzunligi5ga tengelementlarnitoping
string[]group=Array.FindAll(people,rr=> rr.Length== 5);
foreach(varperson ingroup)Console.Write(person+"");
//AbbosNodirOybek Console.ReadKey();
}
}
Elementlarningtartibiniteskarisigao‘zgartiramiz: using System;
classArrayErr
{
staticvoid Main()
{
varpeople=newstring[]{"Ali", "Vali","Abbos","Nodir","Salohiddin","Oybek", "Bekmurod"};
Array.Reverse(people);
for(inti=0;i
Write(people[i]+"");
Console.WriteLine();
Array.Reverse(people,1, 3);
for(inti=0;i
Write(people[i] +""); Console.ReadKey();
}
}
Dasturnatijasidaquyidagiqiymatlar chiqadi
BekmurodOybekSalohiddinNodirAbbosValiAli BekmurodNodirSalohiddinOybekAbbosValiAli Massivlarda foreach sikli
C# da har qanday qiymatlar to‘plamining elementlarini takrorlash uchun ajoyib sikl ishlatiladi. Massiv elementlarini takrorlash uchun shartli va parametrli sikllardan foydalanish mumkin. Masalan, massivning elementlarini ko‘rsatish uchun quyidagicha yozish zarur:
for (int i = 0; i < sort.Length; i++) Console.WriteLine(sotr[i]);
Biroq bunday kod biroz noqulay ko‘rinishi mumkin. Shuning uchun foreach siklidan foydalanish ancha oson:
foreach(string s in sort) Console.WriteLine(s);
Bundaysiklningsintaksisi quyidagicha ko‘rinadi:
|
| |