• Elementlarningtartibiniteskarisigao‘zgartiramiz: using System;
  • Elementnishartbo‘yichatopish: using System




    Download 141,69 Kb.
    bet8/16
    Sana18.05.2024
    Hajmi141,69 Kb.
    #241912
    1   ...   4   5   6   7   8   9   10   11   ...   16
    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:

    Download 141,69 Kb.
    1   ...   4   5   6   7   8   9   10   11   ...   16




    Download 141,69 Kb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Elementnishartbo‘yichatopish: using System

    Download 141,69 Kb.