ValueTuple

ValueTuple

Hikmatullayev Sayidrahmatulloh

C# da ValueTuple.

Tuple bu — bir nechta elmentlardan tuzilgan ma’lumotlar majmuasi .

ValueTuple esa Tuple ni qiymat turini ifodalaydi.

Tuple va ValueTuple ni solishtirib ko’raylik.

li]:relative [&>li]:ps-[2.25ch] [&>li>div_div]:mt-0 [&>li>.bullet]:before:bg-dark/6 [&>li>.bullet]:before:absolute [&>li>.bullet]:before:left-0 [&>li>.bullet]:before:w-[1ch] [&>li>.bullet]:before:h-[1lh] [&>li>.bullet]:before:[mask-repeat:no-repeat] [&>li>.bullet]:before:[mask-position:left] dark:[&>li>.bullet]:before:bg-light/6 [&>li>.bullet:before]:bullet-circleFilled [&_&>li>.bullet:before]:bullet-circle [&_&_&>li>.bullet:before]:bullet-dash [&_&_&_&>li>.bullet:before]:bullet-squareFilled [&_&_&_&_&>li>.bullet:before]:bullet-square [&_&_&_&_&_&>li>.bullet:before]:bullet-circleFilled max-w-3xl w-full mx-auto [&>a]:text-periwinkle-700 [&>a:hover]:text-periwinkle-800 [&>code]:bg-periwinkle-700/4 [&>code]:text-inherit [&>code]:shadow-none text-periwinkle-900 fill-periwinkle-700 stroke-periwinkle-700 dark:text-periwinkle-200 dark:[&>a]:text-periwinkle dark:[&>a:hover]:text-periwinkle-600 dark:[&>code]:bg-periwinkle-200/2 dark:[&>code]:text-inherit decoration-periwinkle-700/6 dark:decoration-periwinkle/6 dark:fill-periwinkle-400 dark:stroke-periwinkle-400 flip-heading-hash»>
  • 1.Tuple malum biror son elementlar ketma-ketligi ifodalanadi , ValueTuple esa elementlar qiymatlari turini ifodalash mumkin turi.

  • 2.Tuple larda nol kompanentali kortej yaratishga ruxsat berilmagan , ValueTuple da bunday kartej yaratish mumkin.

  • 3.ValueTuple elementlari o’zgaruvchan .Tuple ning elementlari esa faqat o’qish ushun.

  • ValueTuple yaratish strukturasi:

    a]:text-periwinkle-700 [&>a:hover]:text-periwinkle-800 [&>code]:bg-periwinkle-700/4 [&>code]:text-inherit [&>code]:shadow-none text-periwinkle-900 fill-periwinkle-700 stroke-periwinkle-700 dark:text-periwinkle-200 dark:[&>a]:text-periwinkle dark:[&>a:hover]:text-periwinkle-600 dark:[&>code]:bg-periwinkle-200/2 dark:[&>code]:text-inherit decoration-periwinkle-700/6 dark:decoration-periwinkle/6 dark:fill-periwinkle-400 dark:stroke-periwinkle-400 flip-heading-hash»>ValuTuple(T1)

    ValueTuple(T1,T2)

    a]:text-periwinkle-700 [&>a:hover]:text-periwinkle-800 [&>code]:bg-periwinkle-700/4 [&>code]:text-inherit [&>code]:shadow-none text-periwinkle-900 fill-periwinkle-700 stroke-periwinkle-700 dark:text-periwinkle-200 dark:[&>a]:text-periwinkle dark:[&>a:hover]:text-periwinkle-600 dark:[&>code]:bg-periwinkle-200/2 dark:[&>code]:text-inherit decoration-periwinkle-700/6 dark:decoration-periwinkle/6 dark:fill-periwinkle-400 dark:stroke-periwinkle-400 flip-heading-hash»>.

    a]:text-periwinkle-700 [&>a:hover]:text-periwinkle-800 [&>code]:bg-periwinkle-700/4 [&>code]:text-inherit [&>code]:shadow-none text-periwinkle-900 fill-periwinkle-700 stroke-periwinkle-700 dark:text-periwinkle-200 dark:[&>a]:text-periwinkle dark:[&>a:hover]:text-periwinkle-600 dark:[&>code]:bg-periwinkle-200/2 dark:[&>code]:text-inherit decoration-periwinkle-700/6 dark:decoration-periwinkle/6 dark:fill-periwinkle-400 dark:stroke-periwinkle-400 flip-heading-hash»>ValueTuple( T1,T2,T3,T4.T5,T6,T7,T8)

    ValueTuple ga ham Tuple kabi 8 ta element kiritish mumkin xolos.

    Lekin bu muammoni ValueTuple ichida ValueTuple yaratish orqali hal qilish mumkin.

    Keling ValueTuplega elementlarni kiritish ko’raylik.

    using System;
    namespace dotnetuz
    {
        class Program
        {
            static void Main(string[] args)
            {
                ValueTupleint> t1 = new ValueTupleint>(2021);     // t1 nomli bitta elementli valuetuple ochdik
                ValueTuplestring,string,double> t2 = new ValueTuplestring,string,double>("C#","C++",7.1);
                // t2 nomli 3ta elementli valuetuple ochdik
                ValueTupleint, int, int, int, ValueTupleint, int>> t3 = new ValueTupleint, int, int, int, ValueTupleint, int>>(1, 2, 45, 23,new ValueTupleint, int>(12, 56));
                //t3 nomli 5 elmentli valuetuple ochdik 
                // ko'rib turganingizdek valuetuple ichida valuetuple ochdik
            }
        }
    }

    VauleTuple da ham Tuple kabi Create() funksiyasidan foydalanish mumkin.

    using System;
    namespace dotnetuz
    {
        class Program
        {
            static void Main(string[] args)
            {
                var tuple1 = ValueTuple.Create(); // bo'sh valuetuple yaratdik
                var tuple2=ValueTuple.Create(7.13,"C#","donetuz"); //3ta elementli valuetuple ochdik
                var tuple3 = ValueTuple.Create("C", "C++", "C#", "Python", "Java", "JavaScript", "JavaScript");
            }
        }
    }

    ValueTuple da har bir kortej o’z nomiga xususiyatiga ega bo’lish imkoni bor.

    Buni quyadagi misolda ko’ramiz.

    using System;
    namespace dotnetuz
    {
        class Program
        {
            static void Main(string[] args)
            {
                (string ism, string familya, int yosh) student = ("Sayidrahmatulloh", "Hikmatullayev", 20);
                System.Console.WriteLine(student);
            }
        }
    }

    Qora oynadagi natija.

    (Sayidrahmatulloh, Hikmatullayev, 20)

    ValueTupening ellementlariga murojat qilishni ko’raylik.

    using System;
    namespace dotnetuz
    {
        class Program
        {
            static void Main(string[] args)
            {
                var tuple1 = ("dotnetuz", "Csharp", 2021);
                Console.WriteLine("Sayt :"+tuple1.Item1);
                Console.WriteLine("Dasturlash tili :"+tuple1.Item2);
                Console.WriteLine("Yil :" + tuple1.Item3);
            }
        }
    }

    Qora oynadagi natija.

    Sayt :dotnetuz

    Dasturlash tili :Csharp

    Yil :2021

    ValueTuple ham Tuple kabi elementlariga avtomatik nom beradi .

    Lekin elementlarni o’zmiz nomlasak biz uchun ancha qulay bo’ladi.

    Keling ValueTuple ni elementlarni nomlab murojat qilib koraylik.

    using System;
    namespace dotnetuz
    {
        class Program
        {
            static void Main(string[] args)
            {
                var student = (Ism: "Sayidrahmatulloh", Familya: "Hikmatullayev", Yosh: 20);
                Console.WriteLine("Ismi : "+student.Ism);
                Console.WriteLine("Familyasi : "+student.Familya);
                Console.WriteLine($"Yoshi : {student.Yosh}");
            }
        }
    }

    Qora oynadagi natija:

    Ismi : Sayidrahmatulloh

    Familyasi : Hikmatullayev

    Yoshi : 20

    Keling endi ValueTuple oraqali metod yaratamiz. Metod yaratish dovomida System.Console funksiyasini ishlatishni ko’ramiz.

    using System;
    using static System.Console;
     /// summary>
    /// System.Console ni qoshib oldik
    /// summary>
    namespace dotnetuz
    {
        class Program
        {
            static void Main(string[] args)
            {
                Write(student());   // ko'rib turganingizdek Console.Write emas Write ishlatilgan
                //System.Console bizga shu imkoniyatni beradi.
            }
            static(int ,string ,string ) student()  // metod yaratib oldik
            {
                return (20, "Sayidrahmatulloh", "Hikmatullayev");
            }
        }
    }

    Qora oynadagi natija .

    (20, Sayidrahmatulloh, Hikmatullayev)

    Metod ochilganda ValueTuplening elementlariga murojat qlish avvalgi misollar kabi bo’ladi.

    ValueTupleni quydagi misolda tushintirishga hatrakat qilaman.

    using System; 
    /// summary>
    /// Alibaba nomli metod ochdik
    /// Va Alibaba kompaniya haqida malumotlar kiritish uchun ValueTuple dan foydalandik
    /// summary>
    namespace dotnetuz
    {
        class Program
        {
            static void Main(string[] args)
            {
                var alibaba = Alibaba();
                Console.WriteLine(alibaba.Kompaniya_tarixi);
            }
            static (string Kompaniya_tarixi,string Foydasi,string Nufuzi ) Alibaba()
            {
                var kompaniya_tarixi = "Alibaba Group Holding Limited — Alibaba Group va Alibaba.com sifatida tanilgan, Xitoyning elektron tijorat, chakana savdo,n Internet va texnologiyalarga ixtisoslashgan transmilliy texnologik kompaniyasi. n1999-yil 28-iyunda Chjetszyan shahrining Xanchjou shahrida tashkil etilgan[1].n Kompaniya veb-portallar orqali isteʼmolchidan isteʼmolchiga (C2C),n biznesdan isteʼmolchiga (B2C) va biznesdan biznesga (B2B) savdo xizmatlarini taqdim etadi.n Elektron toʻlov xizmatlari, xarid qilish qidiruv tizimlari va bulutli hisoblash xizmatlari mavjud.n U dunyodagi ko'plab biznes sohalarida turli xil kompaniyalar portfeliga egalik qiladi va ishlaydi[2]. nBuyuk Britaniyaning dunyo bozorini o‘rganuvchi «Kantar» kompaniyasi dunyoning eng qimmat kompaniyalari reytingini e’lon qildi. ";
                var foydasi = "25 mlrd AQSh dollar";
                var nufuzi="Jaxon reytingini kuchli o'ntaligida 'Alibab' turadi ";
                return (kompaniya_tarixi,foydasi,nufuzi);
            }
        }
    }

    Qora oynadagi natija:

    Alibaba Group Holding Limited - Alibaba Group va Alibaba.com sifatida tanilgan, Xitoyning elektron tijorat, chakana savdo, Internet va texnologiyalarga ixtisoslashgan transmilliy texnologik kompaniyasi.

    1999-yil 28-iyunda Chjetszyan shahrining Xanchjou shahrida tashkil etilgan[1].

    Kompaniya veb-portallar orqali iste'molchidan iste'molchiga (C2C), biznesdan iste'molchiga (B2C) va biznesdan biznesga (B2B) savdo xizmatlarini taqdim etadi.

    Elektron to?lov xizmatlari, xarid qilish qidiruv tizimlari va bulutli hisoblash xizmatlari mavjud.

    U dunyodagi ko'plab biznes sohalarida turli xil kompaniyalar portfeliga egalik qiladi va ishlaydi[2].

    Buyuk Britaniyaning dunyo bozorini o'rganuvchi «Kantar» kompaniyasi dunyoning eng qimmat kompaniyalari reytingini e'lon qildi.

    Misolda ko’rganimizdek ValuTuple orqali o’zimiz uchu kerakli ma’lumotlarni qulay tarzda olishimiz mumkin.

    Ya’ni biz o’zimiz uchun ValueTuple dagi qaysi element kerak bo’lsa shu elementadan foydalanishimiz mumkin.

    ValueTuple bizga elementlarni qiymatini o’zgartirish imkoniyatini ham beradi.

    Dasturlash
    ValueTuple