docs(10_Wiki): Topic_Business/General/Graphic/Programming을 Topics/ 하위로 이동
최상위 10_Wiki/Topic_*였던 4개 카테고리 폴더를 10_Wiki/Topics/Topic_* 로 재배치. 콘텐츠 변경 없음(순수 폴더 이동) — Topics/ 하위 나머지 폴더는 이미 지난 커밋에서 전부 정리된 상태(잔존 항목은 에이전트 운영 상태 및 사용자가 보존을 요청한 업데이트0615/무제 3.canvas 뿐).
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
---
|
||||
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).
|
||||
Reference in New Issue
Block a user