--- id: csharp-strings-interpol title: "C# String Interpolation" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["$ string C#", "interpolated strings", "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", "strings", "interpolation"] raw_sources: ["https://www.w3schools.com/cs/cs_strings_interpol.php"] applied_in: [] github_commit: "" --- # [[CSharp String Interpolation]] ## 🎯 한 줄 통찰 (One-line insight) C#'s `$"...{var}..."` interpolated strings (introduced in C# 6) solve the exact same "embed a variable directly in text without manual concatenation" problem that Python's f-strings (`f"...{var}..."`) already solved in this wiki series — same `{}` placeholder mechanism, just a `$` prefix instead of Python's `f` prefix — while C++ still has no first-class equivalent (requiring `std::format` in C++20+ or manual `<<` chaining), making C# the second language in this series (after Python) to bake variable-embedding directly into string literal syntax rather than relying purely on the `+` operator. [S1] ## 🧠 핵심 개념 (Core concepts) - **`$` prefix** — required to enable string interpolation; without it, `{firstName}` would just be literal text, not a placeholder. [S1] - **`{variable}` placeholders** — variable names inside curly braces are substituted with their values directly in the string. [S1] - **No manual spacing needed** — unlike `+` concatenation (which required manually adding a trailing space inside `"John "`), interpolation lets you place spaces naturally between placeholders in the template string. [S1] - **Introduced in C# 6** — a relatively recent addition to the language, not present from C#'s first version. [S1] ## 📖 세부 내용 (Details) - Example: `string firstName = "John"; string lastName = "Doe"; string name = $"My full name is: {firstName} {lastName}"; Console.WriteLine(name);` → `"My full name is: John Doe"`. [S1] ## ⚖️ 모순 및 업데이트 (Contradictions & updates) - **Python의 f-string과 동일한 설계 철학**: `$"...{var}..."`의 `{}` 플레이스홀더 치환 방식이 이전에 위키화한 Topic_Python의 f-string(`f"...{var}..."`)과 접두사 문자만 다를 뿐 동일한 메커니즘이라는 점이 확인됨 — C++는 이 시리즈에서 아직 이런 1급 문자열 보간 문법을 갖추지 못했음(C++20의 std::format 이전까지는 없었음). [S1] - **공백을 수동으로 넣을 필요가 없어짐**: String Concatenation 챕터의 `+` 방식은 `"John "`처럼 문자열 리터럴 안에 공백을 미리 넣어둬야 했지만, 보간 문자열은 템플릿 안에서 자연스럽게 공백을 배치할 수 있다는 점이 개선점으로 확인됨. [S1] ## 🛠️ 적용 사례 (Applied in summary) firstName과 lastName을 `$"My full name is: {firstName} {lastName}"` 형태로 한 줄에 합쳐 출력하는 예제가 원문에서 직접 실전 활용 사례로 제시됨. [S1] ## 💻 코드 패턴 (Code patterns) String interpolation with the `$` prefix — no manual spacing needed (C#): ```csharp string firstName = "John"; string lastName = "Doe"; string name = $"My full name is: {firstName} {lastName}"; Console.WriteLine(name); // "My full name is: John Doe" ``` ## ✅ 검증 상태 및 신뢰도 - **상태:** draft - **검증 단계:** conceptual - **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body) - **신뢰 점수:** 0.84 - **중복 검사 결과:** 신규 생성 (New discovery) ## 🔗 지식 그래프 (Knowledge Graph) - **상위/루트:** [[C# Tutorial]] - **관련 개념:** [[CSharp Strings Concat]], [[CSharp Strings Access]], [[Python F Strings]] - **참조 맥락:** Strings 섹션 — Access Strings 챕터로 이어짐. ## 📚 출처 (Sources) - [S1] W3Schools — C# String Interpolation — https://www.w3schools.com/cs/cs_strings_interpol.php ## 📝 변경 이력 (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "C# String Interpolation" page (Astra wiki-curation, P-Reinforce v3.1 format).