--- id: csharp-arrays title: "C# Arrays" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["array declaration C#", "new keyword arrays", "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", "arrays"] raw_sources: ["https://www.w3schools.com/cs/cs_arrays.php"] applied_in: [] github_commit: "" --- # [[CSharp Arrays]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) C#'s array declaration puts the brackets right after the TYPE (`string[] cars;`), not after the variable name like C's `char cars[4];` β€” a real syntactic divergence hiding under superficial similarity, and the tutorial explicitly documents FOUR equivalent ways to construct the same array (bare braces, `new type[size]`, `new type[size] {...}`, `new type[] {...}`), while also stating a hard rule the C family never needed: if you declare an array first and assign its values LATER (in a separate statement), the `new` keyword becomes MANDATORY β€” omitting it is a compile error, unlike C where separate declaration and initialization of an array is simply not possible with a brace list at all. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Declaration syntax** β€” `type[] variableName;` β€” brackets attach to the TYPE, not the variable name (contrast with C's `type variableName[size];`). [S1] - **Array literal** β€” `string[] cars = {"Volvo", "BMW", "Ford", "Mazda"};` β€” values in a comma-separated, brace-wrapped list. [S1] - **Index access, 0-based** β€” `cars[0]` is the first element, same convention as every prior language in this series. [S1] - **Mutable elements** β€” `cars[0] = "Opel";` overwrites an existing element directly. [S1] - **`.Length` property** β€” no parentheses, matching the string `.Length` property's design (property, not method). [S1] - **Four equivalent construction forms**: `new string[4]` (empty, size 4), `new string[4] {...}` (size + values), `new string[] {...}` (values, size inferred), and bare `{...}` (values, size inferred, no `new`). [S1] - **`new` becomes mandatory when assigning after declaration** β€” `string[] cars; cars = new string[] {"Volvo", "BMW", "Ford"};` works, but `cars = {"Volvo", "BMW", "Ford"};` (without `new`) is a compile error. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Access: `string[] cars = {"Volvo", "BMW", "Ford", "Mazda"}; Console.WriteLine(cars[0]); // Volvo`. [S1] - Modify: `cars[0] = "Opel"; Console.WriteLine(cars[0]); // Opel`. [S1] - Length: `Console.WriteLine(cars.Length); // 4`. [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) - **λŒ€κ΄„ν˜Έκ°€ λ³€μˆ˜λͺ…이 μ•„λ‹ˆλΌ νƒ€μž…μ— λΆ™μŒ**: C의 λ°°μ—΄ 선언은 `char cars[4];`처럼 λŒ€κ΄„ν˜Έκ°€ λ³€μˆ˜λͺ… 뒀에 λΆ™μ—ˆμ§€λ§Œ, C#은 `string[] cars;`처럼 νƒ€μž… λ°”λ‘œ 뒀에 λŒ€κ΄„ν˜Έκ°€ λΆ™λŠ”λ‹€λŠ” 점이 확인됨 β€” ν‘œλ©΄μ μœΌλ‘œ λΉ„μŠ·ν•΄ λ³΄μ΄μ§€λ§Œ μ‹€μ œ 문법 μœ„μΉ˜κ°€ 닀름. [S1] - **μ„ μ–Έ ν›„ λŒ€μž… μ‹œ newκ°€ ν•„μˆ˜κ°€ 됨**: μ„ μ–Έκ³Ό μ΄ˆκΈ°ν™”λ₯Ό 뢄리할 경우(`string[] cars;` 이후 `cars = {...};`) μ€‘κ΄„ν˜Έλ§ŒμœΌλ‘œλŠ” 컴파일 μ—λŸ¬κ°€ λ‚˜κ³  λ°˜λ“œμ‹œ `new string[] {...}`처럼 newλ₯Ό λΆ™μ—¬μ•Ό ν•œλ‹€λŠ” κ·œμΉ™μ΄ 확인됨 β€” CλŠ”μ• μ΄ˆμ— 배열을 μ„ μ–Έ ν›„ 별도 λ¬Έμž₯μ—μ„œ μ€‘κ΄„ν˜Έ 리슀트둜 μž¬ν• λ‹Ήν•˜λŠ” 것 μžμ²΄κ°€ λΆˆκ°€λŠ₯ν•˜λ―€λ‘œ Cμ—λŠ” μ—†λ˜ κ·œμΉ™. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) μžλ™μ°¨ 이름 배열을 μ„ μ–Έν•˜κ³ , 첫 μ›μ†Œλ₯Ό 읽고 λ°”κΎΈκ³ , 길이λ₯Ό ν™•μΈν•˜λŠ” κΈ°λ³Έ 흐름이 μ›λ¬Έμ—μ„œ 직접 μ‹€μ „ ν™œμš© μ‚¬λ‘€λ‘œ μ œμ‹œλ¨. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Four equivalent array construction forms, and the mandatory `new` on later assignment (C#): ```csharp string[] cars1 = new string[4]; // empty, size 4 string[] cars2 = new string[4] {"Volvo", "BMW", "Ford", "Mazda"}; string[] cars3 = new string[] {"Volvo", "BMW", "Ford", "Mazda"}; string[] cars4 = {"Volvo", "BMW", "Ford", "Mazda"}; // no `new` needed here string[] cars5; cars5 = new string[] {"Volvo", "BMW", "Ford"}; // new REQUIRED when assigned separately // cars5 = {"Volvo", "BMW", "Ford"}; // error without new ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.84 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[C# Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[CSharp Break]], [[CSharp Arrays Loop]], [[C Arrays]], [[CPP Arrays]] - **μ°Έμ‘° λ§₯락:** Arrays μ„Ήμ…˜ β€” Loop Through Arrays μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” C# Arrays β€” https://www.w3schools.com/cs/cs_arrays.php ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C# Arrays" page (Astra wiki-curation, P-Reinforce v3.1 format).