Files
2nd/10_Wiki/Dev/Topic_CSharp/CSharp_Conditions_Shorthand.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.9 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-conditions-shorthand C# Short Hand If...Else Programming_Language draft conceptual
ternary operator C#
? : C#
C# 삼항 연산자
B 0.82 2026-07-04 2026-07-04
csharp
programming-language
w3schools
conditions
ternary
https://www.w3schools.com/cs/cs_conditions_shorthand.php

CSharp Conditions Shorthand

🎯 한 줄 통찰 (One-line insight)

The ternary operator syntax variable = (condition) ? expressionTrue : expressionFalse; is identical to C and C++'s ? : operator, and the tutorial demonstrates it by directly collapsing the SAME time/greeting if/else example from the previous two chapters into one line — making this chapter function as a running "before/after" refactor of the exact code just taught, rather than a standalone new example. [S1]

🧠 핵심 개념 (Core concepts)

  • Ternary operator (? :) — called "short-hand if...else" here, consists of three operands (hence "ternary"), replacing a full if/else block with a single expression. [S1]
  • Syntax: variable = (condition) ? expressionTrue : expressionFalse;. [S1]
  • Use case — best suited for SIMPLE if/else logic that just assigns one of two values; not intended to replace complex multi-branch logic. [S1]

📖 세부 내용 (Details)

  • Full if/else form (identical to the else chapter's example): int time = 20; if (time < 18) { Console.WriteLine("Good day."); } else { Console.WriteLine("Good evening."); }. [S1]
  • Ternary equivalent: int time = 20; string result = (time < 18) ? "Good day." : "Good evening."; Console.WriteLine(result); — produces the identical output in one line instead of five. [S1]

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

  • C/C++의 삼항 연산자와 문법이 동일: (condition) ? expressionTrue : expressionFalse 문법이 C/C++와 차이가 없다는 점이 확인됨. [S1]
  • 바로 앞 챕터(else)의 예제를 그대로 재사용해 리팩터링으로 제시: 새로운 예제를 만들지 않고 else 챕터의 time/greeting 코드를 그대로 가져와 5줄을 1줄로 줄이는 "before/after" 형태로 가르친다는 점이 확인됨 — 개념을 처음부터 다시 설명하지 않고 직전 학습 내용을 압축하는 방식. [S1]

🛠️ 적용 사례 (Applied in summary)

if...else 5줄짜리 시간대 인사말 코드를 삼항 연산자 한 줄로 압축하는 리팩터링 예제가 원문에서 직접 실전 활용 사례로 제시됨. [S1]

💻 코드 패턴 (Code patterns)

Full if/else vs. ternary shorthand — same output (C#):

// Full if/else (5 lines)
int time = 20;
if (time < 18) { Console.WriteLine("Good day."); }
else { Console.WriteLine("Good evening."); }

// Ternary shorthand (1 line)
string result = (time < 18) ? "Good day." : "Good evening.";
Console.WriteLine(result);

검증 상태 및 신뢰도

  • 상태: 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# Short Hand If...Else" page (Astra wiki-curation, P-Reinforce v3.1 format).