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]
대괄호가 변수명이 아니라 타입에 붙음: 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#):
string[]cars1=newstring[4];// empty, size 4string[]cars2=newstring[4]{"Volvo","BMW","Ford","Mazda"};string[]cars3=newstring[]{"Volvo","BMW","Ford","Mazda"};string[]cars4={"Volvo","BMW","Ford","Mazda"};// no `new` needed herestring[]cars5;cars5=newstring[]{"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)