--- id: csharp-method-parameters-default title: "C# Default Parameter Value" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["optional parameter C#", "default value = C#", "C# 기본 매개변수 값"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.83 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["csharp", "programming-language", "w3schools", "methods", "default-parameters"] raw_sources: ["https://www.w3schools.com/cs/cs_method_parameters_default.php"] applied_in: [] github_commit: "" --- # [[CSharp Default Parameter Value]] ## 🎯 한 줄 통찰 (One-line insight) The `=` default-value syntax (`string country = "Norway"`) is identical to C++'s default parameter syntax already covered in Topic_CPP — the strict positional-matching rule from the previous chapter ("same number of arguments as parameters") gets its FIRST exception here: calling `MyMethod()` with zero arguments is now valid specifically because the parameter itself supplies a fallback, making "optional parameter" and "default parameter value" two names for the exact same mechanism. [S1] ## 🧠 핵심 개념 (Core concepts) - **Default parameter value** — assigned with `=` in the method signature: `static void MyMethod(string country = "Norway")`. [S1] - **"Optional parameter"** — the tutorial's alternate name for a parameter with a default value; calling the method WITHOUT that argument is now valid (breaking the prior chapter's strict count-matching rule). [S1] - **Overriding the default** — passing an explicit argument still overrides the default value normally. [S1] ## 📖 세부 내용 (Details) - `static void MyMethod(string country = "Norway") { Console.WriteLine(country); } ... MyMethod("Sweden"); MyMethod("India"); MyMethod(); MyMethod("USA");` → outputs `Sweden`, `India`, `Norway` (default used when no argument given), `USA`. [S1] ## ⚖️ 모순 및 업데이트 (Contradictions & updates) - **인자 개수 일치 규칙의 첫 예외**: Method Parameters 챕터에서 확립된 "인자 개수가 매개변수 개수와 정확히 일치해야 한다"는 규칙이, 기본값이 있는 매개변수에 한해 예외적으로 완화된다는 점이 확인됨 — `MyMethod();`처럼 인자 없이 호출해도 유효함. [S1] - **C++의 기본 매개변수 문법과 동일**: `=` 기호로 기본값을 지정하는 문법이 Topic_CPP의 Default Parameters 챕터와 차이가 없다는 점이 확인됨. [S1] ## 🛠️ 적용 사례 (Applied in summary) country 매개변수에 기본값 "Norway"를 지정한 뒤, 인자를 주거나 주지 않고 네 번 호출하는 예제가 원문에서 직접 실전 활용 사례로 제시됨. [S1] ## 💻 코드 패턴 (Code patterns) Default parameter value — makes the argument optional (C#): ```csharp static void MyMethod(string country = "Norway") { Console.WriteLine(country); } static void Main(string[] args) { MyMethod("Sweden"); // Sweden MyMethod(); // Norway (default used) MyMethod("USA"); // USA } ``` ## ✅ 검증 상태 및 신뢰도 - **상태:** draft - **검증 단계:** conceptual - **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body) - **신뢰 점수:** 0.83 - **중복 검사 결과:** 신규 생성 (New discovery) ## 🔗 지식 그래프 (Knowledge Graph) - **상위/루트:** [[C# Tutorial]] - **관련 개념:** [[CSharp Method Parameters]], [[CSharp Method Parameters Named Args]], [[CPP Function Default]] - **참조 맥락:** Methods 섹션 — Named Arguments 챕터로 이어짐. ## 📚 출처 (Sources) - [S1] W3Schools — C# Default Parameter Value — https://www.w3schools.com/cs/cs_method_parameters_default.php ## 📝 변경 이력 (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C# Default Parameter Value" page (Astra wiki-curation, P-Reinforce v3.1 format).