27. Value va Reference Type (Advanced)

sunnat_qayumov

Sunnat Qayumov

Posted on October 16, 2024

27. Value va Reference Type (Advanced)

a) C# da struct va class orasidagi asosiy farq nimada?

    Struct - bu value type. U stack xotirasida saqlanadi va 
    qiymatni o'zlashtirganda nusxasi o'tkaziladi.
    Class - bu reference type. U heap xotirasida saqlanadi va 
    qiymatni o'zlashtirganda faqat reference (manzil) nusxa 
    qilinadi.
Enter fullscreen mode Exit fullscreen mode

b) Quyidagi kod qanday natija beradi?

    struct Point
    { 
        public int X;
        public int Y;
    }
    Point p1 = new Point():
    p1.X = 10;
    p1.Y = 20;
    Point p2 = p1;
    p2.X = 30;
    Console. WriteLine(p1.X);
Enter fullscreen mode Exit fullscreen mode

bu yerda p1.X ning qiymati chiqariladi, va bu qiymat 10
bo‘ladi, chunki p1.X ning qiymati o‘zgarmagan.

💖 💪 🙅 🚩
sunnat_qayumov
Sunnat Qayumov

Posted on October 16, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related