Skip to content

[Everyday C#] PR 10 — Strings: overview, raw strings, nameof#53676

Open
BillWagner wants to merge 5 commits into
dotnet:mainfrom
BillWagner:strings-overview
Open

[Everyday C#] PR 10 — Strings: overview, raw strings, nameof#53676
BillWagner wants to merge 5 commits into
dotnet:mainfrom
BillWagner:strings-overview

Conversation

@BillWagner
Copy link
Copy Markdown
Member

@BillWagner BillWagner commented May 11, 2026

PR 10 of the EverydayCSharp Fundamentals restructuring. Creates a new Strings section with three articles plus snippet projects and a TOC entry. Purely additive — no moves, no redirects (PRs 11/12 handle the migrations and their redirects).

Steps

  1. Verify baseline. Confirm docs/csharp/fundamentals/null-safety/ is present (template source) and docs/csharp/fundamentals/strings/ is absent. No changes.
  2. Create three snippet projects under docs/csharp/fundamentals/strings/snippets/{strings-overview,raw-string-literals,nameof}/ — each with a .csproj mirroring the null-safety template (net10.0, NRT, implicit usings, Exe) and a Program.cs containing // <SnippetID> regions for every example. Verify each runs locally with dotnet run. Steps 2a/2b/2c are independent of each other.
  3. Author strings/index.md (ms.topic: overview): what a string is, immutability, literals (regular/escape/\e/verbatim), brief UTF-8 (u8) section, char/indexing note, common-operations table (prose only — no links to future PR 11/12 articles), see-also. Strong recommendation: prefer string keyword. Depends on step 2a.
  4. Author strings/raw-string-literals.md (ms.topic: concept-article): why raw strings, single-line, multiline + indentation rule, more-than-three quotes, raw interpolated ($"""/$$"""), when to choose raw vs verbatim vs regular. Strong recommendation: prefer raw for any string with quotes/backslashes/multiline. Depends on step 2b.
  5. Author strings/nameof.md (ms.topic: concept-article): what it does, argument validation (ThrowIfNull then nameof for ArgumentException), INotifyPropertyChanged usage, nameof in attributes (extended scope, used without explanation), unbound generics (C# 14, mentioned), what it returns for qualified names, recommendation to prefer nameof over identifier strings. Depends on step 2c.
  6. Update docs/csharp/toc.yml — insert a new Strings group with three entries immediately after the existing Null safety block (around line 85), before Object-oriented programming. Depends on steps 3–5.
  7. Cross-reference & template pass. Walk each article against its template (template-overview.md / template-concept.md); confirm the four-tier [!TIP] audience block is present and routes Java/C++ readers and beginners; confirm ai-usage: ai-assisted; confirm no F1/helpviewer keys. Depends on steps 3–5.
  8. Style & link-hygiene pass. Confirm every snippet uses Everyday C# features (file-scoped namespaces, NRT, target-typed new, collection expressions, raw strings where natural). Confirm no consecutive snippets in any article. Grep for any links to the future-PR paths (fundamentals/strings/{interpolation,search,split,concatenate,modify,compare}.md, fundamentals/tutorials/string-interpolation.md) and remove if present. Depends on step 7.

Relevant files

Verification

  1. From each docs/csharp/fundamentals/strings/snippets/*/ folder, run dotnet run. Capture each program's output in the PR description (per repo guideline: standalone harness for verification, snippet remains the minimal published subset).
  2. Run the markdown-links-verifier; confirm no broken relative links and no xref resolution failures (especially <xref:System.String>, <xref:System.Text.StringBuilder>, <xref:System.ArgumentNullException.ThrowIfNull%2A>).
  3. After pushing, watch the OpenPublishing.Build status check for warnings; resolve any introduced by this PR before requesting review.
  4. In the build preview, click through the new Strings TOC entries; confirm articles render and :::code::: includes resolve.
  5. grep the three new .md files for any of the future-PR paths listed in step 8 to confirm none slipped in.
  6. Confirm ai-usage: ai-assisted appears in all three articles and no F1/helpviewer keywords are present.

Decisions

  • ~9 files total: 3 articles + 3 Program.cs + 3 .csproj + toc.yml (within the ≤10-file PR rule).
  • No redirects (no moves in this PR).
  • Mention introduction version only for C# 12–14 features (\e C# 13, unbound generics in nameof C# 14). Don't call out C# 6/11 introductions in prose.
  • Strong recommendations (per "gently opinionated" Goal 9, with justification each time):
    • Prefer the string keyword over String — consistency with other built-in keywords; no using System dependency.
    • Prefer raw string literals when a string contains quotes, backslashes, or multiline content — eliminates escape noise and reads cleaner.
    • Prefer nameof over hardcoded identifier strings — compiler-verified, refactor-safe, zero runtime cost.
  • Excluded from this PR: interpolation article, five string how-tos, interpolation tutorial (PRs 11/12). Custom interpolated string handlers, allocation avoidance, Span<char> manipulation beyond a brief mention (deferred to Focus/Advanced per Decision 2).
  • Snippet style: file-based top-level-statements Program.cs per article. For the nameof examples that need attributes on members (e.g., [NotNullIfNotNull(nameof(input))]), keep them inside a top-level Program.cs by declaring helper methods/types after the top-level statements — still a single file-based program.

Further considerations

  1. UTF-8 (u8) coverage in the overview. Project map says "discuss in HTTP context." Recommendation: one short subsection with a single example producing a ReadOnlySpan<byte> for an HTTP body. Alternative: omit entirely and defer to a future Focus article.
  2. StringBuilder mention. Recommendation: prose-only note in the immutability section, no dedicated subsection. The "when to use StringBuilder vs interpolation vs Concat" decision lives in the future coding-style/design-alternatives.md (PR 29) and concatenate.md (PR 12).
  3. nameof vs [CallerArgumentExpression] framing. Recommendation: show ArgumentNullException.ThrowIfNull (which uses [CallerArgumentExpression] internally) as the modern default for null guards, then introduce nameof for the cases the helpers don't cover (ArgumentException, PropertyChanged, attribute arguments). If you'd rather keep the article focused tightly on nameof and skip the ThrowIfNull framing, say the word.

Internal previews

📄 File 🔗 Preview link
docs/csharp/fundamentals/strings/index.md C# strings
docs/csharp/fundamentals/strings/nameof.md The nameof operator
docs/csharp/fundamentals/strings/raw-string-literals.md "Raw string literals in C#"
docs/csharp/toc.yml Taken from https://github.com/dotnet/roslyn/wiki/Samples-and-Walkthroughs

Copilot AI review requested due to automatic review settings May 11, 2026 14:17
@dotnetrepoman dotnetrepoman Bot added this to the May 2026 milestone May 11, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Strings section to the C# Fundamentals docs, including three new articles and supporting snippet projects, and wires the new content into the main C# TOC.

Changes:

  • Added a new Strings node to docs/csharp/toc.yml with entries for Overview, Raw string literals, and nameof.
  • Added three new Fundamentals articles under docs/csharp/fundamentals/strings/.
  • Added three new snippet projects (one per article) under docs/csharp/fundamentals/strings/snippets/.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
docs/csharp/toc.yml Adds the new Strings section and links to the three new articles.
docs/csharp/fundamentals/strings/index.md New strings overview article referencing the overview snippet project.
docs/csharp/fundamentals/strings/raw-string-literals.md New raw string literals concept article referencing the raw-string-literals snippet project (one include currently points at the wrong source file).
docs/csharp/fundamentals/strings/nameof.md New nameof concept article referencing the nameof snippet project.
docs/csharp/fundamentals/strings/snippets/strings-overview/strings-overview.csproj New snippet project for the strings overview article (matches template settings).
docs/csharp/fundamentals/strings/snippets/strings-overview/Program.cs Overview examples for string basics, immutability, literals, UTF-8 literals, indexing, and equality.
docs/csharp/fundamentals/strings/snippets/raw-string-literals/raw-string-literals.csproj New snippet project for the raw string literals article (matches template settings).
docs/csharp/fundamentals/strings/snippets/raw-string-literals/Program.cs Raw string literal examples: single-line, multiline, indentation, quote runs, and raw interpolation.
docs/csharp/fundamentals/strings/snippets/nameof/nameof.csproj New snippet project for the nameof article (matches template settings).
docs/csharp/fundamentals/strings/snippets/nameof/Program.cs nameof examples for basic usage, guard clauses, ThrowIfNull, INotifyPropertyChanged, attributes, unbound generics, and qualified names.

Comment thread docs/csharp/fundamentals/strings/raw-string-literals.md Outdated
Comment thread docs/csharp/fundamentals/strings/snippets/nameof/Program.cs Outdated
Comment thread docs/csharp/fundamentals/strings/snippets/nameof/Program.cs Outdated
Comment thread docs/csharp/fundamentals/strings/nameof.md Outdated
Comment thread docs/csharp/fundamentals/strings/index.md Outdated
Comment thread docs/csharp/fundamentals/strings/index.md Outdated
BillWagner and others added 3 commits May 11, 2026 11:38
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Proofread and add definitions for terms.
@BillWagner BillWagner marked this pull request as ready for review May 12, 2026 20:22
@BillWagner BillWagner requested a review from a team as a code owner May 12, 2026 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants