--- id: csharp-syntax title: "C# Syntax" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["using System", "namespace class Main", "C# 문법"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.86 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["csharp", "programming-language", "w3schools", "syntax"] raw_sources: ["https://www.w3schools.com/cs/cs_syntax.php"] applied_in: [] github_commit: "" --- # [[CSharp Syntax]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) C# mandates that EVERY line of executable code live inside a `class` β€” there is no C-style bare top-level `int main()`, no C++-style free function outside any class β€” which means C#'s minimal program has a mandatory extra nesting layer (`namespace` β†’ `class` β†’ `Main` method) that neither C nor C++ required, and the tutorial explicitly flags one specific Java-vs-C# difference unprompted: unlike Java, the C# filename does NOT have to match the class name (even though convention usually makes them match anyway). [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **`using System;`** β€” imports the System namespace, enabling unqualified use of its classes (e.g. `Console` instead of `System.Console`). [S1] - **`namespace`** β€” a container for classes and other namespaces, used to organize code. [S1] - **`class`** β€” a container for data and methods; ALL executable C# code must be inside a class, with no exception (unlike C's free-standing `main()` or C++'s optional free functions). [S1] - **Curly braces `{}`** β€” mark the beginning/end of every code block (namespace body, class body, method body). [S1] - **`Main` method** β€” the entry point; code inside its braces is what actually executes when the program runs. [S1] - **`Console.WriteLine()`** β€” a method of the `Console` class (part of the `System` namespace) used to print text; omitting `using System;` requires the fully-qualified `System.Console.WriteLine()` instead. [S1] - **Semicolons mandatory** β€” every C# statement ends with `;`. [S1] - **Case-sensitivity** β€” `MyClass` and `myclass` are distinct identifiers. [S1] - **Filename vs. class name** β€” unlike Java (where the public class name MUST match the filename), C# does not enforce this; matching them is convention only, and the saved file must end in `.cs`. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Full annotated example, line by line: `using System;` (namespace import) β†’ blank line (ignored whitespace, used for readability) β†’ `namespace HelloWorld` (organizational container) β†’ `{` (block start) β†’ `class Program` (mandatory class wrapper) β†’ `static void Main(string[] args)` (entry point, keywords deferred to later chapters) β†’ `Console.WriteLine("Hello World!");` (the actual output statement). [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **λͺ¨λ“  μ‹€ν–‰ μ½”λ“œκ°€ λ°˜λ“œμ‹œ class μ•ˆμ— μžˆμ–΄μ•Ό 함**: CλŠ” μ΅œμƒμœ„ ν•¨μˆ˜(`int main()`)λ₯Ό, C++λŠ” 클래슀 λ°–μ˜ 자유 ν•¨μˆ˜(free function)도 ν—ˆμš©ν–ˆμ§€λ§Œ, C#은 μ‹€ν–‰λ˜λŠ” λͺ¨λ“  μ½”λ“œ 쀄이 λ°˜λ“œμ‹œ class 내뢀에 μžˆμ–΄μ•Ό ν•œλ‹€λŠ” μ œμ•½μ΄ λͺ…μ‹œμ μœΌλ‘œ 확인됨 β€” namespaceβ†’classβ†’Mainμ΄λΌλŠ” ν•„μˆ˜ 3쀑 쀑첩 ꡬ쑰. [S1] - **파일λͺ…κ³Ό 클래슀λͺ… μΌμΉ˜κ°€ Java와 달리 κ°•μ œλ˜μ§€ μ•ŠμŒ**: 원문이 직접 "Unlike Java, the name of the C# file does not have to match the class name"이라고 λͺ…μ‹œ β€” JavaλŠ” public 클래슀λͺ…κ³Ό 파일λͺ…이 λ°˜λ“œμ‹œ μΌμΉ˜ν•΄μ•Ό ν•˜λŠ” 반면, C#은 관둀일 뿐 κ°•μ œ κ·œμΉ™μ΄ μ•„λ‹˜μ΄ 확인됨. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) 이전 챕터(Get Started)μ—μ„œ λ“±μž₯ν•œ λ™μΌν•œ Hello World λ³΄μΌλŸ¬ν”Œλ ˆμ΄νŠΈλ₯Ό ν•œ 쀄씩 λΆ„ν•΄ μ„€λͺ…ν•˜λŠ” 것이 이번 μ±•ν„°μ˜ μ‹€μ „ ν™œμš© μ‚¬λ‘€λ‘œ μ œμ‹œλ¨. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Minimal C# program structure β€” namespace/class/Main nesting is mandatory (C#): ```csharp using System; namespace HelloWorld { class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); } } } ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.86 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C# Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CSharp Get Started]], [[CSharp Output]], [[Java Intro]], [[CPP Namespaces]] - **μ°Έμ‘° λ§₯락:** Basics μ„Ήμ…˜ β€” Output μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C# Syntax β€” https://www.w3schools.com/cs/cs_syntax.php ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C# Syntax" page (Astra wiki-curation, P-Reinforce v3.1 format).