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.
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
---
|
||||
id: csharp-constructors
|
||||
title: "C# Constructors"
|
||||
category: "Programming_Language"
|
||||
status: "draft"
|
||||
verification_status: "conceptual"
|
||||
canonical_id: ""
|
||||
aliases: ["default constructor C#", "constructor parameters C#", "C# 생성자"]
|
||||
duplicate_of: ""
|
||||
source_trust_level: "B"
|
||||
confidence_score: 0.85
|
||||
created_at: 2026-07-04
|
||||
updated_at: 2026-07-04
|
||||
review_reason: ""
|
||||
merge_history: []
|
||||
tags: ["csharp", "programming-language", "w3schools", "oop", "constructors"]
|
||||
raw_sources: ["https://www.w3schools.com/cs/cs_constructors.php"]
|
||||
applied_in: []
|
||||
github_commit: ""
|
||||
---
|
||||
|
||||
# [[CSharp Constructors]]
|
||||
|
||||
## 🎯 한 줄 통찰 (One-line insight)
|
||||
The "constructors save time" comparison at the end of this chapter directly rewrites the SAME Ford/Opel two-object example already shown across Class Members and Multiple Classes chapters — turning 8 lines of manual field assignment (`Ford.model = "Mustang"; Ford.color = "red"; Ford.year = 1969;` ×2) into 2 lines of parameterized construction (`new Car("Mustang", "Red", 1969)`), making constructors the payoff for a pattern this wiki has now seen written out the long way THREE times before finally being shown the short way — identical in spirit to C++'s constructor mechanism already covered in Topic_CPP, right down to the "name must match the class, no return type" rule and constructor overloading via differing parameter counts. [S1]
|
||||
|
||||
## 🧠 핵심 개념 (Core concepts)
|
||||
- **Constructor** — a special method that initializes an object; called automatically when an object of the class is created (`new Car()`). [S1]
|
||||
- **Naming rule** — the constructor's name MUST match the class name exactly, and it CANNOT have a return type (no `void`, no `int`, nothing). [S1]
|
||||
- **Default constructor** — every class has one even if you don't write it yourself; but the auto-generated one can't set initial field values the way a custom constructor can. [S1]
|
||||
- **Constructor parameters** — a constructor can take parameters just like any method, used to set field values at creation time (`public Car(string modelName) { model = modelName; }`). [S1]
|
||||
- **Multiple parameters** — a constructor can take as many parameters as needed, mapping each to a field. [S1]
|
||||
- **Constructor overloading** — like ordinary methods, constructors can be overloaded with different parameter counts/types. [S1]
|
||||
|
||||
## 📖 세부 내용 (Details)
|
||||
- Parameterless constructor setting a fixed value: `class Car { public string model; public Car() { model = "Mustang"; } static void Main(string[] args) { Car Ford = new Car(); Console.WriteLine(Ford.model); } }` → `"Mustang"`. [S1]
|
||||
- Single-parameter constructor: `public Car(string modelName) { model = modelName; } ... Car Ford = new Car("Mustang");` → `"Mustang"`. [S1]
|
||||
- Multi-parameter constructor: `public Car(string modelName, string modelColor, int modelYear) { model = modelName; color = modelColor; year = modelYear; } ... Car Ford = new Car("Mustang", "Red", 1969);` → `"Red 1969 Mustang"`. [S1]
|
||||
- Before/after comparison: manual field-by-field assignment for `Ford` and `Opel` (8 lines) collapses to `Car Ford = new Car("Mustang", "Red", 1969); Car Opel = new Car("Astra", "White", 2005);` (2 lines) with a parameterized constructor. [S1]
|
||||
|
||||
## ⚖️ 모순 및 업데이트 (Contradictions & updates)
|
||||
- **C++ 생성자 규칙과 동일**: 생성자 이름이 클래스명과 일치해야 하고 반환 타입을 가질 수 없다는 규칙, 그리고 매개변수 개수로 오버로딩할 수 있다는 규칙이 Topic_CPP의 Constructors/Constructors Overloading 챕터와 차이가 없다는 점이 확인됨. [S1]
|
||||
- **이전 챕터들의 수동 필드 대입 패턴이 생성자로 압축됨**: Class Members와 Multiple Classes 챕터에서 반복적으로 보여준 "객체 생성 후 필드를 하나씩 대입"하는 8줄짜리 패턴이, 이번 챕터의 매개변수 생성자를 쓰면 2줄로 줄어든다는 것이 직접적인 비교로 확인됨. [S1]
|
||||
|
||||
## 🛠️ 적용 사례 (Applied in summary)
|
||||
Ford와 Opel 두 Car 객체를 생성자 없이 필드별로 수동 대입하는 방식과, 3개 매개변수를 받는 생성자로 한 줄에 생성하는 방식을 나란히 비교하는 예제가 원문에서 직접 실전 활용 사례로 제시됨. [S1]
|
||||
|
||||
## 💻 코드 패턴 (Code patterns)
|
||||
Manual field assignment vs. parameterized constructor — same result, less code (C#):
|
||||
```csharp
|
||||
// Without constructor
|
||||
Car Ford = new Car();
|
||||
Ford.model = "Mustang"; Ford.color = "red"; Ford.year = 1969;
|
||||
|
||||
// With constructor
|
||||
class Car
|
||||
{
|
||||
public string model, color;
|
||||
public int year;
|
||||
public Car(string modelName, string modelColor, int modelYear)
|
||||
{
|
||||
model = modelName; color = modelColor; year = modelYear;
|
||||
}
|
||||
}
|
||||
Car Ford2 = new Car("Mustang", "Red", 1969);
|
||||
```
|
||||
|
||||
## ✅ 검증 상태 및 신뢰도
|
||||
- **상태:** draft
|
||||
- **검증 단계:** conceptual
|
||||
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
|
||||
- **신뢰 점수:** 0.85
|
||||
- **중복 검사 결과:** 신규 생성 (New discovery)
|
||||
|
||||
## 🔗 지식 그래프 (Knowledge Graph)
|
||||
- **상위/루트:** [[C# Tutorial]]
|
||||
- **관련 개념:** [[CSharp Classes Multi]], [[CSharp Access Modifiers]], [[CPP Constructors]], [[CPP Constructors Overloading]]
|
||||
- **참조 맥락:** Constructors 섹션의 유일 챕터 — Access Modifiers & Properties 섹션으로 이어짐.
|
||||
|
||||
## 📚 출처 (Sources)
|
||||
- [S1] W3Schools — C# Constructors — https://www.w3schools.com/cs/cs_constructors.php
|
||||
|
||||
## 📝 변경 이력 (Change history)
|
||||
- 2026-07-04: Initial draft synthesized from the W3Schools "C# Constructors" page (Astra wiki-curation, P-Reinforce v3.1 format).
|
||||
Reference in New Issue
Block a user