Files
2nd/10_Wiki/Topics/Topic_Programming/Topic_CSharp/CSharp_Properties.md
T
Antigravity Agent 9a135bd19d docs(10_Wiki): Topic_Business/General/Graphic/Programming을 Topics/ 하위로 이동
최상위 10_Wiki/Topic_*였던 4개 카테고리 폴더를 10_Wiki/Topics/Topic_* 로 재배치.
콘텐츠 변경 없음(순수 폴더 이동) — Topics/ 하위 나머지 폴더는 이미 지난 커밋에서
전부 정리된 상태(잔존 항목은 에이전트 운영 상태 및 사용자가 보존을 요청한
업데이트0615/무제 3.canvas 뿐).
2026-07-05 00:44:01 +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).