--- id: csharp-classes title: "C# Classes and Objects" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["new keyword objects C#", "field C#", "C# 클래스와 객체"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.84 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["csharp", "programming-language", "w3schools", "oop", "classes"] raw_sources: ["https://www.w3schools.com/cs/cs_classes.php"] applied_in: [] github_commit: "" --- # [[CSharp Classes]] ## 🎯 한 줄 통찰 (One-line insight) The chapter's own explicit aside — "it is common that the name of the C# file and the class matches... However it is not required (like in Java)" — directly repeats the exact comparison already flagged in the Syntax chapter, meaning W3Schools' C# tutorial itself considers this Java contrast important enough to state TWICE across the series; the object-creation syntax `Car myObj = new Car();` is otherwise structurally identical to C++'s heap-allocation `new` (though C# never requires a matching `delete` — memory is garbage-collected, a fact not yet stated in this chapter but implied by its complete absence). [S1] ## 🧠 핵심 개념 (Core concepts) - **`class` keyword** — defines a class, e.g. `class Car { string color = "red"; }`. [S1] - **Field** — a variable declared directly inside a class; also called an "attribute". [S1] - **Naming convention (again)** — class names should start uppercase (good practice, not enforced); file name matching class name is common but, unlike Java, NOT required. [S1] - **Object creation** — `ClassName objectName = new ClassName();`, e.g. `Car myObj = new Car();`. [S1] - **Dot syntax** — `myObj.color` accesses a field on an object instance. [S1] ## 📖 세부 내용 (Details) - Class with a field: `class Car { string color = "red"; }`. [S1] - Full object creation + field access example: `class Car { string color = "red"; static void Main(string[] args) { Car myObj = new Car(); Console.WriteLine(myObj.color); } }` → outputs `"red"`. [S1] ## ⚖️ 모순 및 업데이트 (Contradictions & updates) - **Java와의 파일명 대비가 시리즈에서 두 번째로 반복됨**: Syntax 챕터에서 이미 "C#은 Java와 달리 파일명과 클래스명이 일치할 필요가 없다"고 언급했는데, 이번 Classes 챕터가 동일한 비교를 다시 명시적으로 반복한다는 점이 확인됨 — W3Schools가 이 차이를 중요하게 여겨 두 번 강조. [S1] - **new 키워드는 C++와 문법이 같지만 delete 짝이 없음**: `new Car()`가 C++의 힙 할당 `new`와 문법상 동일해 보이지만, 이 챕터(그리고 이후 챕터들)에서 `delete`에 대응하는 언급이 전혀 등장하지 않는다는 점이 확인됨 — C#의 가비지 컬렉션 기반 메모리 관리를 암시(다만 이 챕터가 명시적으로 설명하지는 않음). [S1] ## 🛠️ 적용 사례 (Applied in summary) Car 클래스에 color 필드를 정의하고, new로 객체를 만들어 점(.) 문법으로 필드 값을 출력하는 예제가 원문에서 직접 실전 활용 사례로 제시됨. [S1] ## 💻 코드 패턴 (Code patterns) Class definition, object creation, and dot-syntax field access (C#): ```csharp class Car { string color = "red"; static void Main(string[] args) { Car myObj = new Car(); Console.WriteLine(myObj.color); // "red" } } ``` ## ✅ 검증 상태 및 신뢰도 - **상태:** draft - **검증 단계:** conceptual - **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body) - **신뢰 점수:** 0.84 - **중복 검사 결과:** 신규 생성 (New discovery) ## 🔗 지식 그래프 (Knowledge Graph) - **상위/루트:** [[C# Tutorial]] - **관련 개념:** [[CSharp OOP]], [[CSharp Class Members]], [[CSharp Syntax]], [[CPP Classes]] - **참조 맥락:** OOP Basics 섹션 — Class Members 챕터로 이어짐. ## 📚 출처 (Sources) - [S1] W3Schools — C# Classes and Objects — https://www.w3schools.com/cs/cs_classes.php ## 📝 변경 이력 (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C# Classes and Objects" page (Astra wiki-curation, P-Reinforce v3.1 format).