Files
2nd/10_Wiki/Topic_Programming/Topic_CSharp/CSharp_Properties.md
T
Antigravity Agent e9cbf23ab5 docs(10_Wiki): Dev 폴더 누락분 반영 — Topic_Programming으로 통합
이전 재구성 작업에서 Dev/ 폴더가 누락되었던 것을 반영.

- Dev/Topic_Programming(중첩 폴더, 78개)은 Dev 자체 최상위 폴더들
  (Architecture/Conventions/Engineering_Intelligence 등)과 완전 중복이라 제거.
- Dev 최상위 엔지니어링 지식 폴더(Architecture/Conventions/Engineering_Intelligence/
  Failure_Library/Generalized_Principles/Language/Pattern_Catalog/Platform_Guides/
  Subsystems, 77개)는 이미 Topic_Programming/Topic_Programming에 더 최신 버전이
  존재해 중복 제거(고유 콘텐츠 1개는 예외 처리하여 이동 보존).
- Dev의 W3Schools 언어 튜토리얼 폴더(Topic_C/CPP/CSS/CSharp/HOWTO/HTML/Java/
  JavaScript/PHP/Python/SQL/W3CSS, 1201개)는 전부 Topic_Programming 하위로 이동.
- 에이전트 운영 상태(.astra/docs)는 그대로 유지, 콘텐츠 폴더만 정리.
- Topic_Programming 최종 문서 수: 2784 → 3985.
2026-07-05 00:39:13 +09:00

5.3 KiB

id, title, category, status, verification_status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, created_at, updated_at, review_reason, merge_history, tags, raw_sources, applied_in, github_commit
id title category status verification_status canonical_id aliases duplicate_of source_trust_level confidence_score created_at updated_at review_reason merge_history tags raw_sources applied_in github_commit
csharp-properties C# Properties (Get and Set) Programming_Language draft conceptual
get set C#
automatic properties C#
encapsulation C#
C# 프로퍼티
B 0.86 2026-07-04 2026-07-04
csharp
programming-language
w3schools
oop
properties
encapsulation
https://www.w3schools.com/cs/cs_properties.php

CSharp Properties

🎯 한 줄 통찰 (One-line insight)

This is the chapter where the .Length-is-a-property-not-a-method observation from way back in the Strings chapter finally gets explained: a C# property is a LANGUAGE-LEVEL construct combining a private field with get/set accessor blocks, and — unlike C++, which has no native property syntax and requires programmers to write plain getName()/setName() METHODS by convention — C# additionally offers "automatic properties" (public string Name { get; set; }) that need no backing field written at all, making encapsulation nearly free syntactically where C++ makes it entirely manual boilerplate. [S1]

🧠 핵심 개념 (Core concepts)

  • Encapsulation — hiding sensitive data by declaring fields private, then exposing controlled access through public get/set methods via properties. [S1]
  • Property — a hybrid of a variable and a method, containing a get accessor and a set accessor. [S1]
  • get accessor — returns the value of the associated private field. [S1]
  • set accessor — assigns a value to the associated private field; the special value keyword represents whatever value is being assigned to the property. [S1]
  • Naming convention — the property should share the field's name but start with an UPPERCASE letter (name field ↔ Name property). [S1]
  • Automatic (shorthand) propertiespublic string Name { get; set; } — no backing field declared manually; the compiler generates one implicitly, producing identical behavior with less code. [S1]
  • Encapsulation benefits — better control over class members, ability to make a field effectively read-only (get-only) or write-only (set-only), flexibility to change internals without breaking external code, and increased data security. [S1]

📖 세부 내용 (Details)

  • Full manual property: class Person { private string name; public string Name { get { return name; } set { name = value; } } }. [S1]
  • Usage: Person myObj = new Person(); myObj.Name = "Liam"; Console.WriteLine(myObj.Name);"Liam" — accessed via the SAME dot syntax as a plain field, even though a get/set pair runs underneath. [S1]
  • Automatic property equivalent: class Person { public string Name { get; set; } } — same usage, same output, but no explicit name field or accessor bodies written. [S1]

⚖️ 모순 및 업데이트 (Contradictions & updates)

  • Strings 챕터의 .Length 프로퍼티 미스터리가 여기서 풀림: Topic_CSharp의 Strings 챕터에서 .Length가 괄호 없는 프로퍼티라고 확인했었는데, 이번 챕터가 프로퍼티의 실제 정의(private 필드 + get/set)를 설명함으로써 그 문법적 정체가 명확해짐. [S1]
  • C++에는 없는 언어 차원의 프로퍼티 문법: C++는 프로퍼티라는 언어 기능이 없어 getName()/setName() 같은 일반 메서드를 관례적으로 작성해야 했지만, C#은 get/set 접근자를 언어 문법으로 제공하며 심지어 자동 프로퍼티({ get; set; })로 백킹 필드조차 생략할 수 있다는 점이 확인됨 — 캡슐화 구현 비용이 C++보다 훨씬 낮음. [S1]

🛠️ 적용 사례 (Applied in summary)

Person 클래스의 private name 필드를 public Name 프로퍼티(get/set)로 감싸 외부에서 myObj.Name으로 안전하게 읽고 쓰는 예제, 그리고 이를 자동 프로퍼티로 축약한 동일 결과의 예제가 원문에서 직접 실전 활용 사례로 제시됨. [S1]

💻 코드 패턴 (Code patterns)

Manual property vs. automatic (shorthand) property — same behavior (C#):

// Manual
class Person
{
    private string name;
    public string Name
    {
        get { return name; }
        set { name = value; }
    }
}

// Automatic (shorthand) -- no backing field written
class PersonShort
{
    public string Name { get; set; }
}

검증 상태 및 신뢰도

  • 상태: draft
  • 검증 단계: conceptual
  • 출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)
  • 신뢰 점수: 0.86
  • 중복 검사 결과: 신규 생성 (New discovery)

🔗 지식 그래프 (Knowledge Graph)

📚 출처 (Sources)

📝 변경 이력 (Change history)

  • 2026-07-04: Initial draft synthesized from the W3Schools "C# Properties (Get and Set)" page (Astra wiki-curation, P-Reinforce v3.1 format).