DEV Community

Shohboz Xurramov
Shohboz Xurramov

Posted on

Property vs field farqi nimada?

C# da "property" va "field" lar o'zlarining o'zaro farqlanadi:

  1. Field: Bu o'zgaruvchi yoki ma'lumotlarni saqlash uchun ishlatiladi. U to'g'ridan-to'g'ri sinfda (class) yaratiladi va uga ma'lum qiymat (value) beriladi. Masalan:
csharp
   public class Person {
       private string name; // Field
   }
Enter fullscreen mode Exit fullscreen mode
  1. Property: Bu "getter" va "setter" (qiymat olish va o'zgartirish) funksiyalari bilan birlashtirilgan o'zgaruvchi. U o'zgaruvchi bilan ishlashni abstraktlashtiradi va uni boshqa kodlar uchun qolaylik bilan nazorat qilish imkonini beradi. Masalan:
public class Person {
       private string name; // Field

       public string Name { // Property
           get { return name; }
           set { name = value; }
       }
   }
Enter fullscreen mode Exit fullscreen mode

Bu shakllarda, "Name" field (name) orqali qo'llaniladi, ammo uni "Name" property orqali qo'llash kodni osonlashtiradi va boshqa funksiyalar bilan birlashtirishni ta'minlaydi.

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

While many AI coding tools operate as simple command-response systems, Qodo Gen 1.0 represents the next generation: autonomous, multi-step problem-solving agents that work alongside you.

Read full post

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay