--- id: csharp-switch title: "C# Switch" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["switch case break default C#", "C# ์Šค์œ„์น˜๋ฌธ"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.82 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["csharp", "programming-language", "w3schools", "switch"] raw_sources: ["https://www.w3schools.com/cs/cs_switch.php"] applied_in: [] github_commit: "" --- # [[CSharp Switch]] ## ๐ŸŽฏ ํ•œ ์ค„ ํ†ต์ฐฐ (One-line insight) The `switch(expression) { case x: ... break; default: ... break; }` skeleton is structurally identical to C/C++'s switch statement โ€” same `case`/`break`/`default` keywords, same "evaluate once, compare against each case" model โ€” making Switch the fourth chapter in the C# series (after Comments, Operators, Special Characters) where the answer to "what's different from C++" is essentially nothing at the syntax level shown here. [S1] ## ๐Ÿง  ํ•ต์‹ฌ ๊ฐœ๋… (Core concepts) - **`switch(expression)`** โ€” evaluated exactly ONCE, then compared against each `case` value in order. [S1] - **`case x:`** โ€” if the switch expression matches `x`, that block's code runs. [S1] - **`break`** โ€” exits the switch block immediately once a match's code has run, preventing execution from continuing into subsequent cases; described as saving execution time by skipping the rest of the block. [S1] - **`default:`** โ€” optional; runs when NO case matches the expression. [S1] ## ๐Ÿ“– ์„ธ๋ถ€ ๋‚ด์šฉ (Details) - Weekday-name example: `switch (day) { case 1: Console.WriteLine("Monday"); break; ... case 7: Console.WriteLine("Sunday"); break; }` with `day = 4` โ†’ outputs `"Thursday"`. [S1] - Default fallback example: `switch (day) { case 6: ...Saturday...; break; case 7: ...Sunday...; break; default: Console.WriteLine("Looking forward to the Weekend."); break; }` with `day = 4` (no matching case) โ†’ outputs `"Looking forward to the Weekend."` via `default`. [S1] ## โš–๏ธ ๋ชจ์ˆœ ๋ฐ ์—…๋ฐ์ดํŠธ (Contradictions & updates) - **switch ๊ตฌ์กฐ๊ฐ€ C/C++์™€ ๋™์ผ**: `switch`/`case`/`break`/`default` ํ‚ค์›Œ๋“œ์™€ ์ „์ฒด ๊ตฌ์กฐ๊ฐ€ C/C++์˜ switch๋ฌธ๊ณผ ์ฐจ์ด๊ฐ€ ์—†๋‹ค๋Š” ์ ์ด ํ™•์ธ๋จ โ€” Comments, Operators, Special Characters์— ์ด์€ ๋„ค ๋ฒˆ์งธ "๊ตฌ์กฐ ๋™์ผ" ์ฑ•ํ„ฐ. [S1] ## ๐Ÿ› ๏ธ ์ ์šฉ ์‚ฌ๋ก€ (Applied in summary) ์š”์ผ ๋ฒˆํ˜ธ(day)๋ฅผ ๋ฐ›์•„ ์š”์ผ ์ด๋ฆ„์„ ์ถœ๋ ฅํ•˜๋Š” switch๋ฌธ๊ณผ, ๋งค์น˜๋˜๋Š” case๊ฐ€ ์—†์„ ๋•Œ default๋กœ ๋„˜์–ด๊ฐ€๋Š” ์˜ˆ์ œ๊ฐ€ ์›๋ฌธ์—์„œ ์ง์ ‘ ์‹ค์ „ ํ™œ์šฉ ์‚ฌ๋ก€๋กœ ์ œ์‹œ๋จ. [S1] ## ๐Ÿ’ป ์ฝ”๋“œ ํŒจํ„ด (Code patterns) Switch with break and default (C#): ```csharp int day = 4; switch (day) { case 1: Console.WriteLine("Monday"); break; case 4: Console.WriteLine("Thursday"); break; default: Console.WriteLine("Looking forward to the Weekend."); break; } // Outputs "Thursday" ``` ## โœ… ๊ฒ€์ฆ ์ƒํƒœ ๋ฐ ์‹ ๋ขฐ๋„ - **์ƒํƒœ:** draft - **๊ฒ€์ฆ ๋‹จ๊ณ„:** conceptual - **์ถœ์ฒ˜ ์‹ ๋ขฐ๋„:** B (W3Schools โ€” widely used educational reference, not a primary standards body) - **์‹ ๋ขฐ ์ ์ˆ˜:** 0.82 - **์ค‘๋ณต ๊ฒ€์‚ฌ ๊ฒฐ๊ณผ:** ์‹ ๊ทœ ์ƒ์„ฑ (New discovery) ## ๐Ÿ”— ์ง€์‹ ๊ทธ๋ž˜ํ”„ (Knowledge Graph) - **์ƒ์œ„/๋ฃจํŠธ:** [[C# Tutorial]] - **๊ด€๋ จ ๊ฐœ๋…:** [[CSharp Conditions Shorthand]], [[CSharp While Loop]], [[CPP Switch]] - **์ฐธ์กฐ ๋งฅ๋ฝ:** Switch ์„น์…˜์˜ ์œ ์ผ ์ฑ•ํ„ฐ โ€” Loops ์„น์…˜์œผ๋กœ ์ด์–ด์ง. ## ๐Ÿ“š ์ถœ์ฒ˜ (Sources) - [S1] W3Schools โ€” C# Switch โ€” https://www.w3schools.com/cs/cs_switch.php ## ๐Ÿ“ ๋ณ€๊ฒฝ ์ด๋ ฅ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C# Switch" page (Astra wiki-curation, P-Reinforce v3.1 format).