27. Value va Reference Type (Advanced)
Sunnat Qayumov
Posted on October 16, 2024
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.
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);
bu yerda p1.X ning qiymati chiqariladi, va bu qiymat 10
bo‘ladi, chunki p1.X ning qiymati o‘zgarmagan.
💖 💪 🙅 🚩
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
githubcopilot AI Innovations at Microsoft Ignite 2024 What You Need to Know (Part 2)
November 29, 2024