docs(10_Wiki): 위키 구조 정리 — 언어 튜토리얼 카테고리 폴더 제거 + 신규 자산 동기화
Topic_CSS/Topic_HTML/Topic_JavaScript/Topic_Prompt/Topic_Comfyui 등 기존 카테고리 폴더를 정리하고, Topic_Graphic/Dev 등 신규 산출물과 Topics 내부 세션/메모리 기록을 동기화.
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
---
|
||||
id: csharp-enums
|
||||
title: "C# Enum"
|
||||
category: "Programming_Language"
|
||||
status: "draft"
|
||||
verification_status: "conceptual"
|
||||
canonical_id: ""
|
||||
aliases: ["enumerations C#", "enum switch 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", "enums"]
|
||||
raw_sources: ["https://www.w3schools.com/cs/cs_enums.php"]
|
||||
applied_in: []
|
||||
github_commit: ""
|
||||
---
|
||||
|
||||
# [[CSharp Enums]]
|
||||
|
||||
## 🎯 한 줄 통찰 (One-line insight)
|
||||
`Console.WriteLine(myVar)` on a C# enum prints the symbolic NAME (`"Medium"`), not the underlying integer — a real behavioral difference from C++'s enum, which prints its raw integer value when streamed through `cout <<` unless a custom conversion is written, meaning C# enums carry name-string-printability as a built-in feature (via an implicit `ToString()`) where C++ requires the programmer to bridge that gap manually; the auto-incrementing 0/1/2... numbering and the ability to override a starting value (which cascades to all subsequent members) otherwise matches the C++ enum model already documented in `[[CPP Enum]]`. [S1]
|
||||
|
||||
## 🧠 핵심 개념 (Core concepts)
|
||||
- **`enum` keyword** — declares an enum instead of `class`/`interface`; members separated by commas, no explicit values required. [S1]
|
||||
- **Dot syntax access** — `Level myVar = Level.Medium;` — same pattern as accessing a static class member. [S1]
|
||||
- **Printing an enum prints its NAME** — `Console.WriteLine(myVar);` outputs `"Medium"`, not a number. [S1]
|
||||
- **Default integer values** — the first member is `0`, the second `1`, and so on, incrementing automatically. [S1]
|
||||
- **Explicit cast to get the integer** — `(int) Months.April` is required to retrieve the underlying numeric value; it isn't exposed by default. [S1]
|
||||
- **Custom starting values cascade forward** — assigning a value to one member (e.g. `March = 6`) shifts every SUBSEQUENT member's auto-incremented value accordingly (`April` becomes `7`, not `3`). [S1]
|
||||
- **Enums inside a class** — an enum can be declared as a member of a class, scoped to it. [S1]
|
||||
- **Enums in `switch`** — a natural fit for `switch` statements, matching each `case` against an enum member. [S1]
|
||||
- **Use case** — values known never to change: month names, weekdays, colors, card suits, etc. [S1]
|
||||
|
||||
## 📖 세부 내용 (Details)
|
||||
- Basic declaration + access: `enum Level { Low, Medium, High } ... Level myVar = Level.Medium; Console.WriteLine(myVar);` → `"Medium"`. [S1]
|
||||
- Enum inside a class: `class Program { enum Level { Low, Medium, High } static void Main(string[] args) { Level myVar = Level.Medium; Console.WriteLine(myVar); } }` → `"Medium"`. [S1]
|
||||
- Default numbering + explicit cast: `enum Months { January, February, March, April, May, June, July } ... int myNum = (int) Months.April;` → `3` (0-indexed). [S1]
|
||||
- Custom starting value cascading: `enum Months { January, February, March=6, April, May, June, July } ... int myNum = (int) Months.April;` → `7` (March=6 shifts April to 7, not the default 3). [S1]
|
||||
- Switch on enum: `switch(myVar) { case Level.Low: ...; break; case Level.Medium: Console.WriteLine("Medium level"); break; case Level.High: ...; break; }` → `"Medium level"`. [S1]
|
||||
|
||||
## ⚖️ 모순 및 업데이트 (Contradictions & updates)
|
||||
- **enum을 출력하면 이름이 나옴(C++와 다름)**: C++에서 enum을 `cout <<`으로 출력하면 기본적으로 정수값이 나오지만(별도 변환 없이는 이름이 출력되지 않음), C#은 `Console.WriteLine(myVar)`가 곧바로 심볼릭 이름("Medium")을 출력한다는 점이 확인됨 — C#의 enum이 기본적으로 문자열 표현을 내장하고 있음을 보여줌. [S1]
|
||||
- **자동 증가·수동 재지정 방식은 C++의 enum과 동일**: 첫 멤버가 0부터 시작해 자동 증가하고, 특정 멤버에 값을 수동으로 지정하면 그 이후 멤버들이 그 값을 기준으로 다시 증가한다는 규칙이 `[[CPP Enum]]`에서 확인된 C++ enum 규칙과 차이가 없다는 점이 확인됨. [S1]
|
||||
|
||||
## 🛠️ 적용 사례 (Applied in summary)
|
||||
Level enum(Low/Medium/High)을 switch문에서 각 case와 매칭시켜 해당 레벨 메시지를 출력하는 예제가 원문에서 직접 실전 활용 사례로 제시됨. [S1]
|
||||
|
||||
## 💻 코드 패턴 (Code patterns)
|
||||
Printing an enum prints its name; explicit cast needed for the integer value (C#):
|
||||
```csharp
|
||||
enum Level { Low, Medium, High }
|
||||
|
||||
Level myVar = Level.Medium;
|
||||
Console.WriteLine(myVar); // "Medium" -- name, not a number
|
||||
|
||||
int myNum = (int) Level.Medium; // explicit cast required
|
||||
Console.WriteLine(myNum); // 1
|
||||
```
|
||||
|
||||
## ✅ 검증 상태 및 신뢰도
|
||||
- **상태:** draft
|
||||
- **검증 단계:** conceptual
|
||||
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
|
||||
- **신뢰 점수:** 0.84
|
||||
- **중복 검사 결과:** 신규 생성 (New discovery)
|
||||
|
||||
## 🔗 지식 그래프 (Knowledge Graph)
|
||||
- **상위/루트:** [[C# Tutorial]]
|
||||
- **관련 개념:** [[CSharp Interface Multi]], [[CSharp Switch]], [[CSharp User Input]], [[CPP Enum]]
|
||||
- **참조 맥락:** Enums 섹션의 유일 챕터 — User Input 섹션으로 이어짐.
|
||||
|
||||
## 📚 출처 (Sources)
|
||||
- [S1] W3Schools — C# Enum — https://www.w3schools.com/cs/cs_enums.php
|
||||
|
||||
## 📝 변경 이력 (Change history)
|
||||
- 2026-07-04: Initial draft synthesized from the W3Schools "C# Enum" page (Astra wiki-curation, P-Reinforce v3.1 format).
|
||||
Reference in New Issue
Block a user