Files
2nd/10_Wiki/Dev/Topic_CSharp/CSharp_Arrays_Loop.md
T
Antigravity Agent 1cfd3bbb56 docs(10_Wiki): 위키 구조 정리 — 언어 튜토리얼 카테고리 폴더 제거 + 신규 자산 동기화
Topic_CSS/Topic_HTML/Topic_JavaScript/Topic_Prompt/Topic_Comfyui 등 기존 카테고리 폴더를 정리하고,
Topic_Graphic/Dev 등 신규 산출물과 Topics 내부 세션/메모리 기록을 동기화.
2026-07-05 00:10:59 +09:00

3.8 KiB

id, title, category, status, verification_status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, created_at, updated_at, review_reason, merge_history, tags, raw_sources, applied_in, github_commit
id title category status verification_status canonical_id aliases duplicate_of source_trust_level confidence_score created_at updated_at review_reason merge_history tags raw_sources applied_in github_commit
csharp-arrays-loop C# Loop Through Arrays Programming_Language draft conceptual
for loop array C#
foreach array C#
C# 배열 순회
B 0.82 2026-07-04 2026-07-04
csharp
programming-language
w3schools
arrays
loops
https://www.w3schools.com/cs/cs_arrays_loop.php

CSharp Arrays Loop

🎯 한 줄 통찰 (One-line insight)

This chapter directly recycles the exact foreach example already shown in the Loops section's Foreach chapter — same cars array, same code — but now frames it explicitly AGAINST the indexed for loop alternative, making an explicit value judgment the earlier chapter didn't state outright: foreach is "easier to write... does not require a counter... more readable," a direct trade-off statement this wiki hasn't seen phrased this bluntly for C or C++'s equivalent range-based loops. [S1]

🧠 핵심 개념 (Core concepts)

  • Indexed for loop over an array — uses .Length as the loop bound: for (int i = 0; i < cars.Length; i++) { Console.WriteLine(cars[i]); }. [S1]
  • foreach loop over an array — no counter, no .Length, no index: foreach (string i in cars) { Console.WriteLine(i); }. [S1]
  • Explicit trade-off statedforeach is easier to write, doesn't need a counter, and is more readable than the indexed for — a direct recommendation, not just a neutral alternative. [S1]

📖 세부 내용 (Details)

  • Indexed loop: string[] cars = {"Volvo", "BMW", "Ford", "Mazda"}; for (int i = 0; i < cars.Length; i++) { Console.WriteLine(cars[i]); }. [S1]
  • Foreach loop (identical to the earlier Foreach Loop chapter's own example): string[] cars = {"Volvo", "BMW", "Ford", "Mazda"}; foreach (string i in cars) { Console.WriteLine(i); }. [S1]
  • Reading aid: "for each string element (called i — as in index) in cars, print out the value of i." [S1]

⚖️ 모순 및 업데이트 (Contradictions & updates)

  • foreach가 for보다 명시적으로 권장됨: 이전 Foreach Loop 챕터는 foreach를 단순히 소개만 했지만, 이번 챕터는 for와 나란히 비교하며 "카운터가 필요 없고 더 읽기 쉽다"고 명시적으로 우위를 선언한다는 점이 확인됨 — 두 방식이 동등한 대안이 아니라 foreach가 권장되는 선택임을 분명히 함. [S1]

🛠️ 적용 사례 (Applied in summary)

동일한 자동차 이름 배열을 인덱스 기반 for 루프와 foreach 루프 두 가지로 순회해 비교하는 예제가 원문에서 직접 실전 활용 사례로 제시됨. [S1]

💻 코드 패턴 (Code patterns)

Indexed for loop vs. foreach — same output, different readability (C#):

string[] cars = {"Volvo", "BMW", "Ford", "Mazda"};

for (int i = 0; i < cars.Length; i++)
{
    Console.WriteLine(cars[i]);
}

foreach (string i in cars)
{
    Console.WriteLine(i);
}

검증 상태 및 신뢰도

  • 상태: draft
  • 검증 단계: conceptual
  • 출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)
  • 신뢰 점수: 0.82
  • 중복 검사 결과: 신규 생성 (New discovery)

🔗 지식 그래프 (Knowledge Graph)

📚 출처 (Sources)

📝 변경 이력 (Change history)

  • 2026-07-04: Initial draft synthesized from the W3Schools "C# Loop Through Arrays" page (Astra wiki-curation, P-Reinforce v3.1 format).