DEV Community

Ozodbek
Ozodbek

Posted on

Access Modifiers | C# da

Assalomu alaykum barchaga. Bugun biz C# dasturlash tilida Access Modifierlar haqida o'rganamiz

S: Access Modifierlar o'zi nima ?

J: Access Modifierlar bu - class, struct, record va shu kabi tiplar ichidagi ma'lumotlarga tashqarida turib murojaat qilish imkoniyatni cheklashga aytiladi.

1 - Access Modifierlar - public, private, protected bularni C# dasturlash tilida keng tarqalgan asosiy access modifierlar hisoblanadi. Access Modifierlar class oldidan va class ichida ishlatilishi mumkin.

*2 - * _ Public - Boshqa namespace lardan turib ishlatishga access beradi. U shunday yoziladi.

**public** static class Car 
{
     **public** string color { get; set; }
}
Enter fullscreen mode Exit fullscreen mode

Ushbu codedagi malumotlarni va classni o'zini endi istalgan namespace orqali chaqirishimiz mumkin. Faqatgina shu bir biriga ulangan projectlar bir biriga reference qila olsa...

protected - bu faqat o'zini farzandlariga ko'rinadi. Yani inheritance qilingandagina ko'rinadi. Misol uchun sizda Program.cs va Car.cs file bolsa. Car.cs ichida qandaydir mashina haqida malumotlarni qabul qilgan class mavjud bo'lsa, demak siz protected orqali shu file ichida istalgancha andoza olib ishlatish imkoniga egasiz. Lekin Program.cs file ichida xuddi shu classni chaqirmoqchi bo'lsangiz, 100% xatolik beradi. Haqqingiz yo'q chaqirishga degan ma'noda.

private - esa, sizga umuman qattiq cheklov o'rnatadi. Faqatgina shu bitta classingiz ichida ishlata olasiz xolos, u ma'lumotlarni. private so'zidan ham bilib olish mumkin qanchalik qattiq turishini.

Tushuntira oldimmi ?

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay