--- id: csharp-variables-constants title: "C# Constants" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["const keyword 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", "constants"] raw_sources: ["https://www.w3schools.com/cs/cs_variables_constants.php"] applied_in: [] github_commit: "" --- # [[CSharp Constants]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) C#'s `const` keyword is placed BEFORE the type (`const int myNum = 15;`), exactly mirroring C's `const int` and C++'s identical placement β€” but C# adds a strictness neither predecessor enforces at the same chapter level: a `const` MUST be initialized at declaration, with no separate "declare now, assign later" escape hatch, producing a hard compiler error ("A const field requires a value to be provided") rather than the vaguer undefined/uninitialized-value risk C's const-without-init could silently create. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **`const` keyword** β€” placed before the variable type, makes the variable unchangeable and read-only after its initial assignment. [S1] - **Mandatory initialization** β€” a `const` MUST be assigned a value at the point of declaration; declaring one without a value is a compile error. [S1] - **Use case** β€” values that should never change, like PI (3.14159...), protecting code from accidental overwrites by the same or other developers. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Declaration + illegal reassignment: `const int myNum = 15; myNum = 20; // error`. [S1] - Explicit error message quoted from the compiler: "A const field requires a value to be provided" when a const is declared without a value. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **μ΄ˆκΈ°ν™” μ—†λŠ” const 선언이 ν•˜λ“œ μ—λŸ¬λ‘œ μ¦‰μ‹œ 차단됨**: C의 `const int x;`λŠ” μ„ μ–Έ μžμ²΄λŠ” ν—ˆμš©λ˜κ³  이후 λŒ€μž…μ΄ λΆˆκ°€λŠ₯ν•΄ μ΄ˆκΈ°ν™”λ˜μ§€ μ•Šμ€ 값이 λ‚¨λŠ” μœ„ν—˜μ΄ μžˆμ—ˆμ§€λ§Œ, C#은 μ΄ˆκΈ°ν™” μ—†λŠ” const μ„ μ–Έ 자체λ₯Ό 컴파일 μ—λŸ¬λ‘œ λͺ…μ‹œμ μœΌλ‘œ μ°¨λ‹¨ν•œλ‹€λŠ” 점이 이번 μ±•ν„°μ—μ„œ 확인됨. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” PI처럼 μ ˆλŒ€ λ³€ν•˜μ§€ μ•Šμ•„μ•Ό ν•˜λŠ” κ°’μ˜ μ˜ˆμ‹œλ‘œ const μ‚¬μš©μ΄ μ›λ¬Έμ—μ„œ 언급됨. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) const requires initialization at declaration β€” no exceptions (C#): ```csharp const int myNum = 15; myNum = 20; // error - cannot assign to a const variable ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.84 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C# Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CSharp Variables Identifiers]], [[CSharp Variables Display]], [[C Constants]] - **μ°Έμ‘° λ§₯락:** Variables μ„Ήμ…˜ β€” Display Variables μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C# Constants β€” https://www.w3schools.com/cs/cs_variables_constants.php ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C# Constants" page (Astra wiki-curation, P-Reinforce v3.1 format).