diff --git a/SAMPLES-REPORT.md b/SAMPLES-REPORT.md new file mode 100644 index 00000000000000..82a636d09622fc --- /dev/null +++ b/SAMPLES-REPORT.md @@ -0,0 +1,430 @@ +# Collections XML Docs & Samples Report + +> **Note:** This report documents the initial collections pilot and is not intended +> as a long-term repo asset. It captures decisions, tradeoffs, and context that are +> useful during review of this branch but can be deleted once the work is merged. + +## Overview + +This branch (`dev/richlander/collections-xmldocs`) migrates XML documentation and +adds runnable code samples for the core `System.Collections.Generic` types. The +work spans two library assemblies and covers 11 types with 352 mapped API members. + +The migration was performed with the [`slash` CLI toolkit](https://github.com/richlander/slash-slash-slash-ftw), +which audits, quality-checks, and merges XML documentation from `dotnet-api-docs` +into C# `///` comments and links runnable samples via `samples.json`. + +### Design goals + +Three properties of the tool are central to the workflow: + +- **Any scope** — the tool can be run against a single file, a directory, a library, + or the whole repo. This makes it equally useful for one-type interactive work and + fleet-scale batch processing. + +- **Repeatable with no unique edits in C# source** — the `///` comments written to + `.cs` files are entirely derived from other sources: `dotnet-api-docs` XML, + `samples.json`, and the sample `.cs` files. The tool can be re-run any number of + times without losing data or human effort. This means we can re-run on a fresh + branch to avoid merge conflicts, regenerate after upstream XML doc improvements, + or replay after samples are added — the `.cs` doc comments are always a computed + output, never a hand-maintained artifact. + +- **Built for agent fleets** — the tool and its companion + [agent skill](https://github.com/richlander/slash-slash-slash-ftw/blob/main/SKILL.md) + are purpose-built for multi-agent automation. Each type is an independent work unit: + a doc agent audits, writes samples, registers them in `samples.json`, and runs the + tool to regenerate — no coordination with other agents required. The skill document + describes triage-lead, doc-agent, and reviewer roles that can run in parallel. + + **Rough fleet estimate:** the `dotnet-api-docs` repo contains ~18,000 type-level XML + files. Excluding frameworks not in `dotnet/runtime` (WinForms, WPF, WCF, ASP.NET + WebForms, etc.) leaves an estimated 8,000–10,000 runtime-relevant types. The + collections pilot processed 11 types (352 members, 11 sample files) — each type + taking roughly 15–30 minutes of agent time end-to-end (audit, sample authoring, + merge, verify). At that rate, a fleet of 20 parallel agents could process the full + runtime corpus in approximately 4–8 days of wall-clock time. Doc-only migration + (without writing new samples) is significantly faster — under a minute per type — + and could cover the full set in hours. + + **Open constraint: sample prioritization.** No analysis has been done yet on how to + select which types should get samples first. Not every type benefits equally — high-traffic + APIs (collections, IO, networking) are far more valuable to sample than rarely-used + internal types. An initial rollout should define criteria for high-value samples (e.g., + page-view data from learn.microsoft.com, NuGet download counts, or API usage telemetry) + and use that to rank the work. Without this, a fleet would produce thousands of samples + of uniform effort but uneven impact. This prioritization analysis should be completed + before scaling beyond the pilot. + +## What was added + +### Samples infrastructure + +Each library with samples has a `samples/` directory containing: + +- **`Directory.Build.props`** — isolates samples from the repo build system + (`TargetFramework=net11.0`, `IsSourceProject=false`, `TreatWarningsAsErrors=false`). +- **`Directory.Build.targets`** — empty, blocks repo targets inheritance. +- **`samples.json`** — maps DocFX UIDs (e.g. `M:System.Collections.Generic.List`1.Add`) + to a specific `.cs` file and method name, enabling tooling to link API docs to + runnable examples. +- **`*.Examples.cs`** — standalone file-based apps (top-level statements) that + exercise multiple API members per file. Each file calls local methods, prints + output with `// Output:` comments for expected values, and returns 0 on success. + +### Coverage + +| Type | Assembly | DocFX UIDs | Sample File | Lines | +|------|----------|------------|-------------|-------| +| Dictionary | System.Private.CoreLib | 18 | Dictionary.Examples.cs | 151 | +| HashSet | System.Private.CoreLib | 17 | HashSet.Examples.cs | 122 | +| List | System.Private.CoreLib | 55 | List.Examples.cs | 234 | +| Queue | System.Private.CoreLib | 16 | Queue.Examples.cs | 102 | +| LinkedList | System.Collections | 24 | LinkedList.Examples.cs | 94 | +| LinkedListNode | System.Collections | 7 | — | — | +| OrderedDictionary | System.Collections | 70 | OrderedDictionary.Examples.cs | 149 | +| PriorityQueue | System.Collections | 24 | PriorityQueue.Examples.cs | 108 | +| SortedDictionary | System.Collections | 40 | SortedDictionary.Examples.cs | 117 | +| SortedList | System.Collections | 27 | SortedList.Examples.cs | 164 | +| SortedSet | System.Collections | 29 | SortedSet.Examples.cs | 135 | +| Stack | System.Collections | 24 | Stack.Examples.cs | 128 | +| **Total (11 types)** | | **351** | **11** | **~1,504** | + +### Managing duplication: samples.json vs .cs files + +A key design question is where duplication lives. A single sample function often +demonstrates multiple API members — for example, `AddNodes` in +`LinkedList.Examples.cs` exercises `AddFirst`, `AddLast`, `AddAfter`, and `AddBefore`. +That's one function but six DocFX UIDs that should all link to it. The duplication has +to exist somewhere: either every member's `///` comment contains the full code block, +or only one does and the rest point to it. + +We push duplication into `samples.json` and keep the `.cs` files clean: + +- **`samples.json` is intentionally verbose** — every DocFX UID that a sample covers + gets its own entry, all pointing to the same file and method. LinkedList has 24 + entries for 5 local functions. This is repetitive but explicit: you can look up any + member and immediately see which sample covers it, without needing to read the `.cs` + file or infer grouping. + +- **`.cs` files have no duplication** — each local function appears once. There are no + duplicate code blocks, no copied snippets, no parallel maintenance. The sample file + reads like normal code. + +- **`///` comments use primary/ref to avoid bloat** — when multiple members share a + sample, `samples.json` marks one entry as `"primary": true`. The tool emits the + full `` block on the primary member and a + lightweight `` cross-reference on the others. This keeps the + generated `///` comments small: 20 members can share a sample without 20 copies of + the code block in the source file. + +- **Type-level fallback reduces entries** — constructors and other members that are + naturally demonstrated by a type-level overview sample don't need explicit + `samples.json` entries. The tool automatically considers `T:` entries when looking + up any member of that type. + +The result is that `samples.json` is the only place that knows the many-to-one mapping +from members to functions. It is verbose by design — easy to audit, diff, and +generate — while the `.cs` files stay focused on being readable, runnable code. + +### Sample runner + +`eng/run-samples.sh` discovers and runs every sample, reporting pass/fail: + +``` +$ ./eng/run-samples.sh +Found 11 sample file(s). + + Running System.Collections/.../LinkedList.Examples.cs ... passed + Running System.Collections/.../Stack.Examples.cs ... passed + Running System.Private.CoreLib/.../List.Examples.cs ... passed + ... + +========================================== + Samples: 11 Passed: 11 Failed: 0 +========================================== +``` + +## Source and fidelity to dotnet-api-docs + +The XML documentation was migrated from +[dotnet/dotnet-api-docs](https://github.com/dotnet/dotnet-api-docs). The content +in that repo is the canonical source for .NET API reference documentation shown on +learn.microsoft.com. + +### What was migrated faithfully + +- **`` and `` descriptions** — text was carried over verbatim from + dotnet-api-docs XML, preserving wording, `` references, and + `` usage. +- **`` documentation** — kept as-is from the upstream source. +- **`` tags** — exception documentation was migrated and verified against + the actual source implementation to ensure accuracy. +- **`` content** — longer-form remarks were migrated where they exist in + dotnet-api-docs, converted from raw Markdown to XML doc format. + +### Where samples diverge from dotnet-api-docs + +The code samples in dotnet-api-docs are typically embedded within `` blocks +as non-runnable snippets. The samples in this branch are **new, purpose-built +runnable programs** that differ in several ways: + +1. **Runnable and self-contained** — each `.Examples.cs` file is a complete file-based + app that compiles and runs with `dotnet run`. The dotnet-api-docs snippets are + often fragments that require surrounding context. + +2. **Grouped by usage pattern, not by member** — rather than one tiny snippet per API + member, each sample file groups related members into logical methods + (e.g. `AddAndInsert`, `SearchItems`, `RemoveItems` for List). The `samples.json` + mapping file then associates each DocFX UID with the appropriate method. + +3. **Modern C# idioms** — samples use collection expressions (`[1, 2, 3]`), top-level + statements, `new()` target-typed construction, and other current language features. + The dotnet-api-docs examples often use older C# syntax. + +4. **Output comments** — each `Console.WriteLine` is followed by a `// Output:` comment + showing the expected result, making the samples useful as inline documentation + without running them. + +### Why local functions instead of `#region` + +The established pattern for sample boundaries in .NET — used by +[Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) and supported by the +Sandcastle/DocFX `` attribute — wraps sample code in +`#region`/`#endregion` markers. The doc build system extracts the content between the +markers and injects it into the rendered documentation. + +We deliberately avoided this pattern. Regions are a poor fit for samples, especially +samples that new users will encounter: + +- **Regions are not real code structure** — they are preprocessor directives that the + compiler ignores. A `#region` can start mid-statement, span unrelated code, or depend + on variables declared outside the region. A new user who copies the region content + gets a fragment that may not compile. This is the opposite of what a sample should be. + +- **Regions require invisible scaffolding** — the code inside a `#region` still needs a + containing method, class, and `Main` to compile and run. That scaffolding is outside + the region and invisible in the rendered docs, so the user sees a snippet but not what + it takes to actually run it. Local functions in a top-level program are complete — a + reader can copy the function and run it with `dotnet run`. + +- **Regions aren't standard or pretty** — `#region`/`#endregion` markers are visual + noise that most style guides discourage in production code. Putting them in samples + signals that this is an acceptable pattern, which it isn't. New users learning from + samples should not be picking up `#region` as an idiom. + +- **Regions are fragile at scale** — during fleet processing, agents occasionally + insert `// ` comment markers, `#region` directives, or other boundary conventions + when instructed to "mark sample boundaries." Local functions are unambiguous — there + is no creative interpretation of what a boundary looks like. + +We chose **local functions** with a `method="..."` attribute instead. A local function +has a clear scope (parameters, local variables, return), is self-contained and +copy-pasteable, and is already runnable — which is what makes `eng/run-samples.sh` +possible. Adding `#region` markers on top of functions would be redundant nesting with +no benefit. + +The tradeoff is that `method="..."` is not a standard DocFX attribute today. If the +runtime's doc build pipeline is extended to render these samples, it would need to +support extracting local function bodies — a straightforward addition (parse the file, +find the function, emit its body) but not yet implemented. The +[`dotnet-inspect` sample-references doc](https://github.com/richlander/dotnet-inspect/blob/main/docs/sample-references.md) +surveys the `region`-based and other patterns across the ecosystem for additional +context. + +## Branch history + +| Commit | Description | +|--------|-------------| +| `06e32c5` | Scaffold `samples/` directories with `Directory.Build.props`, `Directory.Build.targets`, and empty `samples.json` for both libraries | +| `3c02b72` | Add samples for List, Dictionary, HashSet, Queue (System.Private.CoreLib) | +| `e347a6c` | Add samples for Stack, LinkedList, SortedSet, PriorityQueue (System.Collections) | +| `8c1bd5a` | Add samples for SortedDictionary, SortedList, OrderedDictionary (System.Collections) | +| `ca912aa` | Add `eng/run-samples.sh` sample runner script | + +## How eng/run-samples.sh works + +The script is a standalone Bash utility with no MSBuild integration. It: + +1. **Discovers samples** — uses `find` to locate all `*.Examples.cs` files under + `src/libraries/*/samples/`. + +2. **Resolves the build context** — for each file, walks up the directory tree to find + the enclosing `samples/` directory (where `Directory.Build.props` lives). This is + the working directory for `dotnet run`. + +3. **Runs each sample** — executes `dotnet run ` using the repo's + `.dotnet` SDK. The file-based app feature in .NET 10+ compiles and runs the `.cs` + file directly. + +4. **Captures results** — stdout/stderr are captured. On failure (non-zero exit code), + the full output is printed indented under the file name. On success, output is + suppressed unless `--verbose` is passed. + +5. **Reports a summary** — prints total/passed/failed counts and lists all failed files. + Exits with code 1 if any sample failed, 0 otherwise. + +### Usage + +```bash +./eng/run-samples.sh # Run all samples, show failures only +./eng/run-samples.sh --verbose # Run all samples, show all output +./eng/run-samples.sh --help # Print help +``` + +### Failure detection + +A sample is considered failed if `dotnet run` returns a non-zero exit code. This +catches: + +- **Explicit failure** — samples that `return 1` (or any non-zero value). +- **Unhandled exceptions** — runtime errors produce a stack trace and a non-zero exit. +- **Compilation errors** — `dotnet run` itself fails with a non-zero exit code if the + file doesn't compile. + +### Ideal: run samples as CI tests + +`eng/run-samples.sh` is a standalone script that works today but is not wired into +the repo's CI pipeline. The ideal end state is for sample failures to break CI, just +like unit tests. Here is what that path looks like: + +1. **Add a `libs.samples` build subset** — register a new subset in `eng/Subsets.props` + alongside `libs.tests`. This gives `./build.sh -s libs.samples` a first-class + entry point without coupling samples to the existing test infrastructure. + +2. **Create an MSBuild project that discovers and runs samples** — a thin `.proj` or + `.targets` file under `eng/testing/` that uses `` to run `dotnet run` on each + `*.Examples.cs` file. This replaces the Bash script with something the existing + build orchestration can schedule, log, and report on natively. + +3. **Integrate into Helix** — the runtime repo runs tests on Helix for cross-platform + coverage. Each sample is a tiny, self-contained workload — ideal for Helix work + items. The MSBuild project would produce Helix payloads the same way library tests + do, giving samples the same OS/arch matrix as the rest of the repo. + +4. **Wire into the libraries pipeline** — add the `libs.samples` subset to the + appropriate legs in `eng/pipelines/`. Samples are fast (compile + run in seconds) + so they can run alongside `libs.tests` without meaningful CI cost. + +5. **Report results in test infrastructure** — emit results in a format the repo's + test reporting understands (TRX or Helix-compatible). This surfaces sample failures + in PR checks and the build dashboard alongside unit test results. + +The current `eng/run-samples.sh` script is the right starting point — it already +handles discovery, execution, and failure reporting. The work is to lift it into the +build system so that the results are visible in the same place as all other test +results and failures block merge. + +## Directory.Build.props isolation tradeoff + +Each `samples/` directory contains a `Directory.Build.props` that replaces the repo's +build-property chain and an empty `Directory.Build.targets` that blocks repo-level +targets inheritance. Together they create a clean isolation boundary so that samples +compile as standalone file-based apps via `dotnet run`. + +### Why isolation is needed + +The runtime repo's `Directory.Build.props` chain imports Arcade SDK orchestration, +strong-name keys, AOT analyzers, trimming props, and project-classification logic. +Those settings assume every project is a library, test, or reference assembly in the +repo's build graph. A plain `.cs` file-based app breaks under those assumptions: + +- **`IsSourceProject` / `IsReferenceAssemblyProject`** — triggers signing, packaging, + and platform-specific build logic that doesn't apply to a sample. +- **`TreatWarningsAsErrors`** — the repo enforces this globally, but samples may use + simplified code that produces nullable or other warnings irrelevant to their purpose. +- **`PublishAot` / `IsAotCompatible`** — the repo enables these for shipping libraries; + they add analyzer overhead and errors for samples that don't need AOT. +- **`TargetFramework` inference** — the repo's TFW pipeline is complex; samples just + need `net11.0`. + +### The tradeoff + +Full isolation means samples don't get *any* repo-level settings — no shared analyzers, +no repo version properties, no common packaging configuration. They are effectively +standalone console apps that happen to live inside the repo tree. This is safe and +simple, but it can silently drift from repo conventions over time. + +### What would change to accept repo settings + +To let the repo's build infrastructure flow through instead: + +1. **Import the parent chain and override selectively** — replace the current + `Directory.Build.props` with one that imports the repo-level file and then overrides + only the properties that break samples (`IsSourceProject`, `PublishAot`, etc.). + Do the same for `.targets`. + +2. **Fix sample warnings instead of suppressing them** — remove the blanket + `TreatWarningsAsErrors=false` and either fix the warnings or suppress specific + codes with ``. + +3. **Remove the hardcoded `TargetFramework`** — let the repo's TFW inference set it, + or use a shared property, so samples stay in sync when the repo rolls forward. + +4. **Validate against the full repo build** — run `build.cmd` / `build.sh` to confirm + that samples aren't pulled into packaging, signing, or CI pipelines. The + `IsSourceProject=false` override should prevent this, but it needs verification + against Arcade's project-discovery logic. + +5. **Update `eng/run-samples.sh`** — if repo settings flow in, samples may need to be + built with the repo SDK (`.dotnet/dotnet`) rather than a global SDK, and the script + may need to pass additional properties or adjust working directories. + +The core tension is that full isolation is fragile to drift (samples silently diverge +from repo conventions) while full inheritance is fragile to breakage (repo build changes +break unrelated samples). The current approach chose isolation as the safer default for +a first pass. + +## Batching work into PRs + +At scale, the migration will produce changes across dozens of libraries. Merging +everything in one PR would be unreviewable, but one PR per type creates too much +overhead. Several batching strategies are viable: + +### Option A: One PR per library (recommended) + +Each PR covers all types within a single library assembly (e.g., `System.Collections`, +`System.Private.CoreLib`, `System.Net.Http`). This is the natural unit because: + +- A library's `samples/` directory, `samples.json`, and `Directory.Build.props` are + self-contained — no cross-library dependencies. +- Reviewers familiar with a library can review all its types together. +- The sample runner can validate just that library's samples before merge. +- PR size stays manageable: the collections pilot covered 11 types across 2 libraries + and the total diff is modest. + +### Option B: One PR per namespace + +For large libraries with many namespaces (e.g., `System.Private.CoreLib` spans +`System`, `System.Collections.Generic`, `System.Threading`, etc.), split by namespace. +This keeps PRs smaller but requires more coordination on shared files like +`samples.json`. + +### Option C: Infrastructure first, then content + +Separate the scaffolding (`Directory.Build.props`, `Directory.Build.targets`, +`samples.json` skeleton, `eng/run-samples.sh`, CI integration) into a single +infrastructure PR. Subsequent PRs add only sample files and `samples.json` entries. +This is useful if the infrastructure needs its own review cycle — especially the +`Directory.Build.props` isolation tradeoff and CI wiring — before the fleet starts +producing content. + +### General guidance + +Regardless of batching strategy: + +- **Doc migration (`///` comments) and samples should ship in the same PR** — they are + produced by the same tool run and validated together. Splitting them risks partial + states where doc comments reference samples that don't exist yet. +- **Re-run the tool on a fresh branch before opening the PR** — since `///` comments + are a computed output (see design goals), regenerating on a fresh branch avoids + merge conflicts with any `main` changes that touched the same files. +- **Include the `slash quality` before/after output in the PR description** — this + gives reviewers a quick summary of what improved without reading every diff line. +- **Re-run after merge to update incrementally** — because `///` comments are derived + and the tool works at any scope, a merged library can be re-run at any time. For + example, after the initial `System.Collections` merge, a follow-up PR could add new + samples, remove outdated ones, or pick up upstream XML doc edits from `dotnet-api-docs` + — just re-run `slash merge` against the same files and only the delta shows up in the + diff. This is especially relevant if `dotnet-api-docs` continues to be edited in + parallel for some transition period. diff --git a/eng/run-samples.sh b/eng/run-samples.sh new file mode 100755 index 00000000000000..b696cfdc7cc3e8 --- /dev/null +++ b/eng/run-samples.sh @@ -0,0 +1,124 @@ +#!/usr/bin/env bash + +set -uo pipefail + +source="${BASH_SOURCE[0]}" +while [[ -h "$source" ]]; do + scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" + source="$(readlink "$source")" + [[ $source != /* ]] && source="$scriptroot/$source" +done +scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" +reporoot="$( cd -P "$scriptroot/.." && pwd )" + +usage() +{ + echo "Usage: run-samples.sh [options]" + echo "" + echo "Discovers and runs all *.Examples.cs sample files under src/libraries/*/samples/." + echo "Each sample is a file-based app executed with 'dotnet run'. A non-zero exit code" + echo "from any sample is treated as a failure." + echo "" + echo "Options:" + echo " --verbose (-v) Show output from every sample, not just failures." + echo " --help (-h) Print this help message." + echo "" + echo "Examples:" + echo " ./eng/run-samples.sh # Run all samples, report failures" + echo " ./eng/run-samples.sh --verbose # Run all samples, show all output" +} + +verbose=false + +while [[ $# -gt 0 ]]; do + opt="$(echo "${1/#--/-}" | tr "[:upper:]" "[:lower:]")" + case "$opt" in + -help|-h|-\?) + usage + exit 0 + ;; + -verbose|-v) + verbose=true + shift 1 + ;; + *) + echo "Unknown option: $1" 1>&2 + usage + exit 1 + ;; + esac +done + +export PATH="$reporoot/.dotnet:$PATH" + +# Verify the SDK is available. +if ! command -v dotnet &> /dev/null; then + echo "error: 'dotnet' not found. Build the repo first (./build.sh) to provision the SDK." + exit 1 +fi + +# Discover all sample files. +mapfile -t sample_files < <(find "$reporoot/src/libraries" -path '*/samples/*/*.Examples.cs' -type f | sort) + +if [[ ${#sample_files[@]} -eq 0 ]]; then + echo "No sample files found." + exit 0 +fi + +echo "Found ${#sample_files[@]} sample file(s)." +echo "" + +passed=0 +failed=0 +declare -a failed_files=() + +for file in "${sample_files[@]}"; do + # Determine the samples/ directory (where Directory.Build.props lives). + samples_dir="${file}" + while [[ "$(basename "$samples_dir")" != "samples" ]]; do + samples_dir="$(dirname "$samples_dir")" + done + + # Build a relative path from the samples dir to the .cs file. + relative_path="${file#"$samples_dir/"}" + + # Friendly display name: library + relative path. + lib_dir="$(dirname "$samples_dir")" + lib_name="$(basename "$lib_dir")" + display_name="$lib_name/samples/$relative_path" + + echo -n " Running $display_name ... " + + # Run the sample from the samples/ directory. + output=$(cd "$samples_dir" && dotnet run "$relative_path" 2>&1) + exit_code=$? + + if [[ $exit_code -eq 0 ]]; then + echo "passed" + ((passed++)) + if [[ "$verbose" == true ]]; then + echo "$output" | sed 's/^/ | /' + fi + else + echo "FAILED (exit code $exit_code)" + ((failed++)) + failed_files+=("$display_name") + echo "$output" | sed 's/^/ | /' + fi +done + +echo "" +echo "==========================================" +echo " Samples: $((passed + failed)) Passed: $passed Failed: $failed" +echo "==========================================" + +if [[ $failed -gt 0 ]]; then + echo "" + echo "Failed samples:" + for f in "${failed_files[@]}"; do + echo " - $f" + done + exit 1 +fi + +exit 0 diff --git a/src/libraries/System.Collections/samples/Directory.Build.props b/src/libraries/System.Collections/samples/Directory.Build.props new file mode 100644 index 00000000000000..d541fc3a2c6e17 --- /dev/null +++ b/src/libraries/System.Collections/samples/Directory.Build.props @@ -0,0 +1,11 @@ + + + + net11.0 + false + false + false + false + false + + diff --git a/src/libraries/System.Collections/samples/Directory.Build.targets b/src/libraries/System.Collections/samples/Directory.Build.targets new file mode 100644 index 00000000000000..8c119d5413b585 --- /dev/null +++ b/src/libraries/System.Collections/samples/Directory.Build.targets @@ -0,0 +1,2 @@ + + diff --git a/src/libraries/System.Collections/samples/System/Collections/Generic/LinkedList.Examples.cs b/src/libraries/System.Collections/samples/System/Collections/Generic/LinkedList.Examples.cs new file mode 100644 index 00000000000000..2a16767b7ed57a --- /dev/null +++ b/src/libraries/System.Collections/samples/System/Collections/Generic/LinkedList.Examples.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; + +AddNodes(); +RemoveNodes(); +FindNodes(); +NavigateNodes(); +CopyToArray(); + +void AddNodes() +{ + var list = new LinkedList(); + + list.AddFirst("B"); + list.AddFirst("A"); + list.AddLast("D"); + + LinkedListNode nodeB = list.Find("B")!; + list.AddAfter(nodeB, "B+"); + list.AddBefore(nodeB, "B-"); + + foreach (string item in list) + Console.Write(item + " "); + Console.WriteLine(); + // Output: A B- B B+ D +} + +void RemoveNodes() +{ + var list = new LinkedList(new[] { "A", "B", "C", "D", "E" }); + + list.RemoveFirst(); + list.RemoveLast(); + list.Remove("C"); + + foreach (string item in list) + Console.Write(item + " "); + Console.WriteLine(); + // Output: B D + + list.Clear(); + Console.WriteLine($"Count after Clear: {list.Count}"); + // Output: Count after Clear: 0 +} + +void FindNodes() +{ + var list = new LinkedList(new[] { 1, 2, 3, 2, 1 }); + + LinkedListNode? first2 = list.Find(2); + LinkedListNode? last2 = list.FindLast(2); + + Console.WriteLine($"Find(2) next: {first2!.Next!.Value}"); + // Output: Find(2) next: 3 + Console.WriteLine($"FindLast(2) next: {last2!.Next!.Value}"); + // Output: FindLast(2) next: 1 + Console.WriteLine($"Contains(3): {list.Contains(3)}"); + // Output: Contains(3): True +} + +void NavigateNodes() +{ + var list = new LinkedList(new[] { "A", "B", "C" }); + + LinkedListNode? node = list.First; + Console.WriteLine($"First: {node!.Value}"); + // Output: First: A + Console.WriteLine($"Last: {list.Last!.Value}"); + // Output: Last: C + Console.WriteLine($"Count: {list.Count}"); + // Output: Count: 3 + + Console.WriteLine($"First.Next: {node.Next!.Value}"); + // Output: First.Next: B + Console.WriteLine($"Last.Previous: {list.Last!.Previous!.Value}"); + // Output: Last.Previous: B + Console.WriteLine($"First.List == list: {node.List == list}"); + // Output: First.List == list: True + + ref string valueRef = ref node.ValueRef; + valueRef = "Z"; + Console.WriteLine($"First after ValueRef mutation: {list.First!.Value}"); + // Output: First after ValueRef mutation: Z +} + +void CopyToArray() +{ + var list = new LinkedList(new[] { 10, 20, 30 }); + int[] array = new int[5]; + list.CopyTo(array, 1); + + Console.WriteLine(string.Join(", ", array)); + // Output: 0, 10, 20, 30, 0 +} diff --git a/src/libraries/System.Collections/samples/System/Collections/Generic/LinkedList.samples.json b/src/libraries/System.Collections/samples/System/Collections/Generic/LinkedList.samples.json new file mode 100644 index 00000000000000..3b59e3a90d3967 --- /dev/null +++ b/src/libraries/System.Collections/samples/System/Collections/Generic/LinkedList.samples.json @@ -0,0 +1,161 @@ +{ + "T:System.Collections.Generic.LinkedList`1": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "AddNodes", + "title": "Adding nodes to a LinkedList", + "primary": true + }, + "M:System.Collections.Generic.LinkedList`1.#ctor": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "RemoveNodes", + "title": "Removing nodes from a LinkedList", + "primary": true + }, + "M:System.Collections.Generic.LinkedList`1.#ctor(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "RemoveNodes", + "title": "Removing nodes from a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.AddFirst(`0)": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "AddNodes", + "title": "Adding nodes to a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.AddFirst(System.Collections.Generic.LinkedListNode{`0})": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "AddNodes", + "title": "Adding nodes to a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.AddLast(`0)": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "AddNodes", + "title": "Adding nodes to a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.AddLast(System.Collections.Generic.LinkedListNode{`0})": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "AddNodes", + "title": "Adding nodes to a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.AddAfter(System.Collections.Generic.LinkedListNode{`0},`0)": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "AddNodes", + "title": "Adding nodes to a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.AddAfter(System.Collections.Generic.LinkedListNode{`0},System.Collections.Generic.LinkedListNode{`0})": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "AddNodes", + "title": "Adding nodes to a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.AddBefore(System.Collections.Generic.LinkedListNode{`0},`0)": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "AddNodes", + "title": "Adding nodes to a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.AddBefore(System.Collections.Generic.LinkedListNode{`0},System.Collections.Generic.LinkedListNode{`0})": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "AddNodes", + "title": "Adding nodes to a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.Remove(`0)": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "RemoveNodes", + "title": "Removing nodes from a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.Remove(System.Collections.Generic.LinkedListNode{`0})": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "RemoveNodes", + "title": "Removing nodes from a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.RemoveFirst": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "RemoveNodes", + "title": "Removing nodes from a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.RemoveLast": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "RemoveNodes", + "title": "Removing nodes from a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.Clear": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "RemoveNodes", + "title": "Removing nodes from a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.Find(`0)": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "FindNodes", + "title": "Finding nodes in a LinkedList", + "primary": true + }, + "M:System.Collections.Generic.LinkedList`1.FindLast(`0)": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "FindNodes", + "title": "Finding nodes in a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.Contains(`0)": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "FindNodes", + "title": "Finding nodes in a LinkedList" + }, + "P:System.Collections.Generic.LinkedList`1.First": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "NavigateNodes", + "title": "Navigating LinkedListNode properties", + "primary": true + }, + "P:System.Collections.Generic.LinkedList`1.Last": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "NavigateNodes", + "title": "Navigating LinkedListNode properties" + }, + "P:System.Collections.Generic.LinkedList`1.Count": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "NavigateNodes", + "title": "Navigating LinkedListNode properties" + }, + "M:System.Collections.Generic.LinkedList`1.CopyTo(`0[],System.Int32)": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "CopyToArray", + "title": "Copying a LinkedList to an array" + }, + "M:System.Collections.Generic.LinkedList`1.GetEnumerator": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "AddNodes", + "title": "Adding nodes to a LinkedList" + }, + "T:System.Collections.Generic.LinkedListNode`1": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "NavigateNodes", + "title": "Navigating LinkedListNode properties" + }, + "M:System.Collections.Generic.LinkedListNode`1.#ctor(`0)": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "NavigateNodes", + "title": "Navigating LinkedListNode properties" + }, + "P:System.Collections.Generic.LinkedListNode`1.Value": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "NavigateNodes", + "title": "Navigating LinkedListNode properties" + }, + "P:System.Collections.Generic.LinkedListNode`1.Next": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "NavigateNodes", + "title": "Navigating LinkedListNode properties" + }, + "P:System.Collections.Generic.LinkedListNode`1.Previous": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "NavigateNodes", + "title": "Navigating LinkedListNode properties" + }, + "P:System.Collections.Generic.LinkedListNode`1.List": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "NavigateNodes", + "title": "Navigating LinkedListNode properties" + }, + "P:System.Collections.Generic.LinkedListNode`1.ValueRef": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "NavigateNodes", + "title": "Navigating LinkedListNode properties" + } +} diff --git a/src/libraries/System.Collections/samples/System/Collections/Generic/OrderedDictionary.Examples.cs b/src/libraries/System.Collections/samples/System/Collections/Generic/OrderedDictionary.Examples.cs new file mode 100644 index 00000000000000..d8440ce9646d6c --- /dev/null +++ b/src/libraries/System.Collections/samples/System/Collections/Generic/OrderedDictionary.Examples.cs @@ -0,0 +1,149 @@ +using System; +using System.Collections.Generic; + +AddAndAccess(); +IndexBasedAccess(); +InsertAndRemove(); +KeysValuesAndEnumerate(); +TryAddAndTryGetValue(); +CapacityManagement(); +ConstructFromCollection(); + +Console.WriteLine("All examples passed."); +return 0; + +void AddAndAccess() +{ + OrderedDictionary dict = new(); + dict.Add("apple", 1); + dict.Add("banana", 2); + dict.Add("cherry", 3); + + Console.WriteLine($"dict[\"banana\"]: {dict["banana"]}"); // 2 + dict["banana"] = 20; + Console.WriteLine($"dict[\"banana\"] after set: {dict["banana"]}"); // 20 + + bool found = dict.TryGetValue("cherry", out int value); + Console.WriteLine($"TryGetValue 'cherry': {found}, value: {value}"); // True, 3 + + Console.WriteLine($"ContainsKey 'apple': {dict.ContainsKey("apple")}"); // True + Console.WriteLine($"ContainsValue 20: {dict.ContainsValue(20)}"); // True + Console.WriteLine($"Count: {dict.Count}"); // 3 +} + +void IndexBasedAccess() +{ + OrderedDictionary dict = new(); + dict.Add("alpha", 10); + dict.Add("bravo", 20); + dict.Add("charlie", 30); + + KeyValuePair entry = dict.GetAt(1); + Console.WriteLine($"GetAt(1): {entry.Key} = {entry.Value}"); // bravo = 20 + + dict.SetAt(1, 25); + Console.WriteLine($"After SetAt(1, 25): {dict.GetAt(1).Value}"); // 25 + + dict.SetAt(1, "beta", 22); + Console.WriteLine($"After SetAt(1, 'beta', 22): {dict.GetAt(1).Key} = {dict.GetAt(1).Value}"); // beta = 22 + + int index = dict.IndexOf("charlie"); + Console.WriteLine($"IndexOf 'charlie': {index}"); // 2 + + dict.RemoveAt(0); + Console.WriteLine($"After RemoveAt(0), first key: {dict.GetAt(0).Key}"); // beta +} + +void InsertAndRemove() +{ + OrderedDictionary dict = new(); + dict.Add("one", 1); + dict.Add("three", 3); + + dict.Insert(1, "two", 2); + Console.WriteLine($"After Insert at 1: {dict.GetAt(1).Key} = {dict.GetAt(1).Value}"); // two = 2 + + bool removed = dict.Remove("one"); + Console.WriteLine($"Remove 'one': {removed}, Count: {dict.Count}"); // True, 2 + + bool removedWithValue = dict.Remove("two", out int removedValue); + Console.WriteLine($"Remove 'two': {removedWithValue}, value: {removedValue}"); // True, 2 + + dict.Clear(); + Console.WriteLine($"After Clear, Count: {dict.Count}"); // 0 +} + +void KeysValuesAndEnumerate() +{ + OrderedDictionary dict = new(); + dict.Add("x", 10); + dict.Add("y", 20); + dict.Add("z", 30); + + Console.WriteLine($"Keys: [{string.Join(", ", dict.Keys)}]"); // x, y, z + Console.WriteLine($"Values: [{string.Join(", ", dict.Values)}]"); // 10, 20, 30 + + Console.Write("Enumerate: "); + foreach (KeyValuePair kvp in dict) + { + Console.Write($"{kvp.Key}={kvp.Value} "); + } + Console.WriteLine(); // x=10 y=20 z=30 +} + +void TryAddAndTryGetValue() +{ + OrderedDictionary dict = new(); + bool added = dict.TryAdd("key1", 100); + Console.WriteLine($"TryAdd 'key1': {added}"); // True + + bool addedAgain = dict.TryAdd("key1", 200); + Console.WriteLine($"TryAdd 'key1' again: {addedAgain}"); // False + + bool addedWithIndex = dict.TryAdd("key2", 200, out int addIndex); + Console.WriteLine($"TryAdd 'key2': {addedWithIndex}, index: {addIndex}"); // True, 1 + + bool found = dict.TryGetValue("key2", out int val, out int idx); + Console.WriteLine($"TryGetValue 'key2': {found}, value: {val}, index: {idx}"); // True, 200, 1 +} + +void CapacityManagement() +{ + OrderedDictionary dict = new(); + int ensured = dict.EnsureCapacity(50); + Console.WriteLine($"EnsureCapacity(50): {ensured}"); // >= 50 + + for (int i = 0; i < 10; i++) + dict.Add($"item{i}", i); + + Console.WriteLine($"Count: {dict.Count}, Capacity: {dict.Capacity}"); // 10, >= 50 + dict.TrimExcess(); + Console.WriteLine($"After TrimExcess, Capacity: {dict.Capacity}"); + + dict.TrimExcess(20); + Console.WriteLine($"After TrimExcess(20), Capacity: {dict.Capacity}"); + Console.WriteLine($"Comparer: {dict.Comparer}"); +} + +void ConstructFromCollection() +{ + Dictionary source = new() + { + ["one"] = 1, + ["two"] = 2, + ["three"] = 3 + }; + OrderedDictionary fromDict = new(source); + Console.WriteLine($"From IDictionary, Count: {fromDict.Count}"); // 3 + + List> pairs = [new("a", 1), new("b", 2)]; + OrderedDictionary fromEnum = new(pairs); + Console.WriteLine($"From IEnumerable, Count: {fromEnum.Count}"); // 2 + + OrderedDictionary withComparer = new(StringComparer.OrdinalIgnoreCase); + withComparer.Add("Hello", 1); + Console.WriteLine($"ContainsKey 'hello': {withComparer.ContainsKey("hello")}"); // True + + OrderedDictionary withCapacity = new(100); + Console.WriteLine($"Capacity from ctor(100): {withCapacity.Capacity}"); // >= 100 +} diff --git a/src/libraries/System.Collections/samples/System/Collections/Generic/OrderedDictionary.samples.json b/src/libraries/System.Collections/samples/System/Collections/Generic/OrderedDictionary.samples.json new file mode 100644 index 00000000000000..56fc1f23bd6f2f --- /dev/null +++ b/src/libraries/System.Collections/samples/System/Collections/Generic/OrderedDictionary.samples.json @@ -0,0 +1,354 @@ +{ + "T:System.Collections.Generic.OrderedDictionary`2": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary", + "primary": true + }, + "M:System.Collections.Generic.OrderedDictionary`2.#ctor(System.Int32)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "ConstructFromCollection", + "title": "Constructing an OrderedDictionary from collections", + "primary": true + }, + "M:System.Collections.Generic.OrderedDictionary`2.#ctor(System.Collections.Generic.IEqualityComparer{`0})": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "ConstructFromCollection", + "title": "Constructing an OrderedDictionary from collections" + }, + "M:System.Collections.Generic.OrderedDictionary`2.#ctor(System.Int32,System.Collections.Generic.IEqualityComparer{`0})": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "ConstructFromCollection", + "title": "Constructing an OrderedDictionary from collections" + }, + "M:System.Collections.Generic.OrderedDictionary`2.#ctor(System.Collections.Generic.IDictionary{`0,`1})": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "ConstructFromCollection", + "title": "Constructing an OrderedDictionary from collections" + }, + "M:System.Collections.Generic.OrderedDictionary`2.#ctor(System.Collections.Generic.IDictionary{`0,`1},System.Collections.Generic.IEqualityComparer{`0})": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "ConstructFromCollection", + "title": "Constructing an OrderedDictionary from collections" + }, + "M:System.Collections.Generic.OrderedDictionary`2.#ctor(System.Collections.Generic.IEnumerable{System.Collections.Generic.KeyValuePair{`0,`1}})": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "ConstructFromCollection", + "title": "Constructing an OrderedDictionary from collections" + }, + "M:System.Collections.Generic.OrderedDictionary`2.#ctor(System.Collections.Generic.IEnumerable{System.Collections.Generic.KeyValuePair{`0,`1}},System.Collections.Generic.IEqualityComparer{`0})": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "ConstructFromCollection", + "title": "Constructing an OrderedDictionary from collections" + }, + "M:System.Collections.Generic.OrderedDictionary`2.Add(`0,`1)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.Item(`0)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.TryGetValue(`0,`1@)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.ContainsKey(`0)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.ContainsValue(`1)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.Count": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.GetAt(System.Int32)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "IndexBasedAccess", + "title": "Index-based access in an OrderedDictionary", + "primary": true + }, + "M:System.Collections.Generic.OrderedDictionary`2.SetAt(System.Int32,`1)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "IndexBasedAccess", + "title": "Index-based access in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.SetAt(System.Int32,`0,`1)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "IndexBasedAccess", + "title": "Index-based access in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.IndexOf(`0)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "IndexBasedAccess", + "title": "Index-based access in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.RemoveAt(System.Int32)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "IndexBasedAccess", + "title": "Index-based access in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.Insert(System.Int32,`0,`1)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "InsertAndRemove", + "title": "Inserting and removing items in an OrderedDictionary", + "primary": true + }, + "M:System.Collections.Generic.OrderedDictionary`2.Remove(`0)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "InsertAndRemove", + "title": "Inserting and removing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.Remove(`0,`1@)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "InsertAndRemove", + "title": "Inserting and removing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.Clear": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "InsertAndRemove", + "title": "Inserting and removing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.Keys": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary", + "primary": true + }, + "P:System.Collections.Generic.OrderedDictionary`2.Values": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.GetEnumerator": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.TryAdd(`0,`1)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "TryAddAndTryGetValue", + "title": "Using TryAdd and TryGetValue with an OrderedDictionary", + "primary": true + }, + "M:System.Collections.Generic.OrderedDictionary`2.TryAdd(`0,`1,System.Int32@)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "TryAddAndTryGetValue", + "title": "Using TryAdd and TryGetValue with an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.TryGetValue(`0,`1@,System.Int32@)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "TryAddAndTryGetValue", + "title": "Using TryAdd and TryGetValue with an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.Capacity": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "CapacityManagement", + "title": "Managing capacity of an OrderedDictionary", + "primary": true + }, + "M:System.Collections.Generic.OrderedDictionary`2.EnsureCapacity(System.Int32)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "CapacityManagement", + "title": "Managing capacity of an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.TrimExcess": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "CapacityManagement", + "title": "Managing capacity of an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.TrimExcess(System.Int32)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "CapacityManagement", + "title": "Managing capacity of an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.Comparer": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "CapacityManagement", + "title": "Managing capacity of an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#ICollection>#Add(System.Collections.Generic.KeyValuePair{`0,`1})": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#ICollection>#Contains(System.Collections.Generic.KeyValuePair{`0,`1})": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#ICollection>#CopyTo(System.Collections.Generic.KeyValuePair{`0,`1}[],System.Int32)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#ICollection>#IsReadOnly": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#ICollection>#Remove(System.Collections.Generic.KeyValuePair{`0,`1})": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "InsertAndRemove", + "title": "Inserting and removing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#IDictionary#Keys": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#IDictionary#Values": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#IEnumerable>#GetEnumerator": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#IList>#IndexOf(System.Collections.Generic.KeyValuePair{`0,`1})": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "IndexBasedAccess", + "title": "Index-based access in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#IList>#Insert(System.Int32,System.Collections.Generic.KeyValuePair{`0,`1})": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "InsertAndRemove", + "title": "Inserting and removing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#IList>#Item(System.Int32)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "IndexBasedAccess", + "title": "Index-based access in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#IReadOnlyDictionary#Keys": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#IReadOnlyDictionary#Values": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#IReadOnlyList>#Item(System.Int32)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "IndexBasedAccess", + "title": "Index-based access in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#ICollection#CopyTo(System.Array,System.Int32)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#ICollection#IsSynchronized": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#ICollection#SyncRoot": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#IDictionary#Add(System.Object,System.Object)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#IDictionary#Contains(System.Object)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#IDictionary#GetEnumerator": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#IDictionary#IsFixedSize": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#IDictionary#IsReadOnly": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#IDictionary#Item(System.Object)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#IDictionary#Keys": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#IDictionary#Remove(System.Object)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "InsertAndRemove", + "title": "Inserting and removing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#IDictionary#Values": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#IEnumerable#GetEnumerator": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#IList#Add(System.Object)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#IList#Contains(System.Object)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#IList#IndexOf(System.Object)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "IndexBasedAccess", + "title": "Index-based access in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#IList#Insert(System.Int32,System.Object)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "InsertAndRemove", + "title": "Inserting and removing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#IList#IsFixedSize": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#IList#IsReadOnly": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#IList#Item(System.Int32)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "IndexBasedAccess", + "title": "Index-based access in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#IList#Remove(System.Object)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "InsertAndRemove", + "title": "Inserting and removing items in an OrderedDictionary" + } +} diff --git a/src/libraries/System.Collections/samples/System/Collections/Generic/PriorityQueue.Examples.cs b/src/libraries/System.Collections/samples/System/Collections/Generic/PriorityQueue.Examples.cs new file mode 100644 index 00000000000000..7c01e88261e7ac --- /dev/null +++ b/src/libraries/System.Collections/samples/System/Collections/Generic/PriorityQueue.Examples.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; + +EnqueueAndDequeue(); +EnqueueDequeueAndDequeueEnqueue(); +EnqueueRangeDemo(); +EnsureCapacityAndTrimExcess(); + +void EnqueueAndDequeue() +{ + var pq = new PriorityQueue(); + + pq.Enqueue("Fix crash", 1); + pq.Enqueue("Code review", 3); + pq.Enqueue("Write tests", 2); + + Console.WriteLine($"Count: {pq.Count}"); + // Output: Count: 3 + + Console.WriteLine($"Peek: {pq.Peek()}"); + // Output: Peek: Fix crash + + if (pq.TryPeek(out string? peekedElement, out int peekedPriority)) + { + Console.WriteLine($"TryPeek: {peekedElement} (priority {peekedPriority})"); + } + // Output: TryPeek: Fix crash (priority 1) + + Console.WriteLine($"Dequeue: {pq.Dequeue()}"); + // Output: Dequeue: Fix crash + + if (pq.TryDequeue(out string? element, out int priority)) + { + Console.WriteLine($"TryDequeue: {element} (priority {priority})"); + } + // Output: TryDequeue: Write tests (priority 2) + + Console.WriteLine($"Count after removals: {pq.Count}"); + // Output: Count after removals: 1 +} + +void EnqueueDequeueAndDequeueEnqueue() +{ + var pq = new PriorityQueue(); + pq.Enqueue("Existing task", 5); + + // EnqueueDequeue adds an element, then removes and returns the minimum. + string result1 = pq.EnqueueDequeue("Urgent task", 1); + Console.WriteLine($"EnqueueDequeue returned: {result1}"); + // Output: EnqueueDequeue returned: Urgent task + + // DequeueEnqueue removes the minimum, then adds a new element. + pq.Enqueue("Low priority", 10); + string result2 = pq.DequeueEnqueue("Medium task", 7); + Console.WriteLine($"DequeueEnqueue returned: {result2}"); + // Output: DequeueEnqueue returned: Existing task + + Console.WriteLine($"Remaining count: {pq.Count}"); + // Output: Remaining count: 2 +} + +void EnqueueRangeDemo() +{ + var pq = new PriorityQueue(); + + // EnqueueRange with element-priority pairs. + pq.EnqueueRange(new (string, int)[] + { + ("Task A", 3), + ("Task B", 1), + ("Task C", 2) + }); + + Console.WriteLine($"Count after EnqueueRange: {pq.Count}"); + // Output: Count after EnqueueRange: 3 + + // EnqueueRange with elements sharing the same priority. + pq.EnqueueRange(new[] { "Task D", "Task E" }, priority: 4); + + Console.WriteLine($"Count after second EnqueueRange: {pq.Count}"); + // Output: Count after second EnqueueRange: 5 + + // Drain the queue to show ordering. + while (pq.TryDequeue(out string? element, out int priority)) + { + Console.WriteLine($" {element} (priority {priority})"); + } + // Output: + // Task B (priority 1) + // Task C (priority 2) + // Task A (priority 3) + // Task D (priority 4) + // Task E (priority 4) +} + +void EnsureCapacityAndTrimExcess() +{ + var pq = new PriorityQueue(); + + int capacity = pq.EnsureCapacity(100); + Console.WriteLine($"Capacity after EnsureCapacity(100): {capacity}"); + // Output: Capacity after EnsureCapacity(100): 100 + + pq.Enqueue("Only item", 1); + pq.TrimExcess(); + Console.WriteLine($"Count after TrimExcess: {pq.Count}"); + // Output: Count after TrimExcess: 1 +} diff --git a/src/libraries/System.Collections/samples/System/Collections/Generic/PriorityQueue.samples.json b/src/libraries/System.Collections/samples/System/Collections/Generic/PriorityQueue.samples.json new file mode 100644 index 00000000000000..a3cd55cb6ffd4e --- /dev/null +++ b/src/libraries/System.Collections/samples/System/Collections/Generic/PriorityQueue.samples.json @@ -0,0 +1,116 @@ +{ + "T:System.Collections.Generic.PriorityQueue`2": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Enqueuing and dequeuing items by priority", + "primary": true + }, + "M:System.Collections.Generic.PriorityQueue`2.#ctor(System.Collections.Generic.IEnumerable{System.ValueTuple{`0,`1}})": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueRangeDemo", + "title": "Initializing and enqueuing ranges of items", + "primary": true + }, + "M:System.Collections.Generic.PriorityQueue`2.#ctor(System.Int32)": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnsureCapacityAndTrimExcess", + "title": "Managing priority queue capacity", + "primary": true + }, + "M:System.Collections.Generic.PriorityQueue`2.#ctor(System.Collections.Generic.IEnumerable{System.ValueTuple{`0,`1}},System.Collections.Generic.IComparer{`1})": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueRangeDemo", + "title": "Initializing and enqueuing ranges of items" + }, + "M:System.Collections.Generic.PriorityQueue`2.#ctor(System.Int32,System.Collections.Generic.IComparer{`1})": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnsureCapacityAndTrimExcess", + "title": "Managing priority queue capacity" + }, + "P:System.Collections.Generic.PriorityQueue`2.Capacity": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnsureCapacityAndTrimExcess", + "title": "Managing priority queue capacity" + }, + "M:System.Collections.Generic.PriorityQueue`2.Clear": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Enqueuing and dequeuing items by priority" + }, + "P:System.Collections.Generic.PriorityQueue`2.Comparer": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Enqueuing and dequeuing items by priority" + }, + "P:System.Collections.Generic.PriorityQueue`2.Count": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Enqueuing and dequeuing items by priority" + }, + "M:System.Collections.Generic.PriorityQueue`2.Dequeue": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Enqueuing and dequeuing items by priority" + }, + "M:System.Collections.Generic.PriorityQueue`2.DequeueEnqueue(`0,`1)": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueDequeueAndDequeueEnqueue", + "title": "Using EnqueueDequeue and DequeueEnqueue", + "primary": true + }, + "M:System.Collections.Generic.PriorityQueue`2.Enqueue(`0,`1)": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Enqueuing and dequeuing items by priority" + }, + "M:System.Collections.Generic.PriorityQueue`2.EnqueueDequeue(`0,`1)": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueDequeueAndDequeueEnqueue", + "title": "Using EnqueueDequeue and DequeueEnqueue" + }, + "M:System.Collections.Generic.PriorityQueue`2.EnqueueRange(System.Collections.Generic.IEnumerable{System.ValueTuple{`0,`1}})": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueRangeDemo", + "title": "Initializing and enqueuing ranges of items" + }, + "M:System.Collections.Generic.PriorityQueue`2.EnqueueRange(System.Collections.Generic.IEnumerable{`0},`1)": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueRangeDemo", + "title": "Initializing and enqueuing ranges of items" + }, + "M:System.Collections.Generic.PriorityQueue`2.EnsureCapacity(System.Int32)": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnsureCapacityAndTrimExcess", + "title": "Managing priority queue capacity" + }, + "M:System.Collections.Generic.PriorityQueue`2.Peek": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Enqueuing and dequeuing items by priority" + }, + "M:System.Collections.Generic.PriorityQueue`2.Remove(`0,`0@,`1@,System.Collections.Generic.IEqualityComparer{`0})": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Enqueuing and dequeuing items by priority" + }, + "M:System.Collections.Generic.PriorityQueue`2.TrimExcess": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnsureCapacityAndTrimExcess", + "title": "Managing priority queue capacity" + }, + "M:System.Collections.Generic.PriorityQueue`2.TryDequeue(`0@,`1@)": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Enqueuing and dequeuing items by priority" + }, + "M:System.Collections.Generic.PriorityQueue`2.TryPeek(`0@,`1@)": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Enqueuing and dequeuing items by priority" + }, + "P:System.Collections.Generic.PriorityQueue`2.UnorderedItems": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueRangeDemo", + "title": "Initializing and enqueuing ranges of items" + } +} diff --git a/src/libraries/System.Collections/samples/System/Collections/Generic/SortedDictionary.Examples.cs b/src/libraries/System.Collections/samples/System/Collections/Generic/SortedDictionary.Examples.cs new file mode 100644 index 00000000000000..4ec59e3921d56c --- /dev/null +++ b/src/libraries/System.Collections/samples/System/Collections/Generic/SortedDictionary.Examples.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections; +using System.Collections.Generic; + +AddAndAccess(); +RemoveAndClear(); +IterateKeysAndValues(); +CopyToArray(); +Constructors(); + +void AddAndAccess() +{ + var scores = new SortedDictionary(); + scores.Add("Alice", 90); + scores.Add("Bob", 85); + scores["Charlie"] = 78; + + Console.WriteLine($"Count: {scores.Count}"); + Console.WriteLine($"Alice's score: {scores["Alice"]}"); + + if (scores.TryGetValue("Bob", out int bobScore)) + Console.WriteLine($"Bob's score: {bobScore}"); + + Console.WriteLine($"ContainsKey(\"Alice\"): {scores.ContainsKey("Alice")}"); + Console.WriteLine($"ContainsValue(78): {scores.ContainsValue(78)}"); + + // Update an existing entry via the indexer + scores["Alice"] = 95; + Console.WriteLine($"Alice's updated score: {scores["Alice"]}"); +} + +void RemoveAndClear() +{ + var colors = new SortedDictionary + { + [1] = "Red", + [2] = "Green", + [3] = "Blue" + }; + + bool removed = colors.Remove(2); + Console.WriteLine($"Removed key 2: {removed}"); + Console.WriteLine($"Count after Remove: {colors.Count}"); + + colors.Clear(); + Console.WriteLine($"Count after Clear: {colors.Count}"); +} + +void IterateKeysAndValues() +{ + var capitals = new SortedDictionary + { + ["France"] = "Paris", + ["Japan"] = "Tokyo", + ["Brazil"] = "Brasília" + }; + + Console.WriteLine("Keys:"); + foreach (string key in capitals.Keys) + Console.WriteLine($" {key}"); + + Console.WriteLine("Values:"); + foreach (string value in capitals.Values) + Console.WriteLine($" {value}"); + + Console.WriteLine("Enumerating key-value pairs:"); + foreach (KeyValuePair kvp in capitals) + Console.WriteLine($" {kvp.Key}: {kvp.Value}"); +} + +void CopyToArray() +{ + var dict = new SortedDictionary + { + ["one"] = 1, + ["two"] = 2, + ["three"] = 3 + }; + + var array = new KeyValuePair[dict.Count]; + dict.CopyTo(array, 0); + + foreach (KeyValuePair kvp in array) + Console.WriteLine($" {kvp.Key} = {kvp.Value}"); +} + +void Constructors() +{ + // Default constructor + var dict1 = new SortedDictionary(); + dict1.Add("cherry", 3); + dict1.Add("apple", 1); + Console.WriteLine($"Default comparer order:"); + foreach (var kvp in dict1) + Console.WriteLine($" {kvp.Key}: {kvp.Value}"); + + // Constructor with a custom comparer (case-insensitive) + var dict2 = new SortedDictionary(StringComparer.OrdinalIgnoreCase); + dict2.Add("Banana", 2); + dict2.Add("apple", 1); + Console.WriteLine($"Comparer: {dict2.Comparer.GetType().Name}"); + foreach (var kvp in dict2) + Console.WriteLine($" {kvp.Key}: {kvp.Value}"); + + // Constructor from an existing dictionary + var source = new Dictionary { ["x"] = 10, ["a"] = 20 }; + var dict3 = new SortedDictionary(source); + Console.WriteLine("Constructed from Dictionary:"); + foreach (var kvp in dict3) + Console.WriteLine($" {kvp.Key}: {kvp.Value}"); + + // Constructor from an existing dictionary with a comparer + var dict4 = new SortedDictionary(source, StringComparer.OrdinalIgnoreCase); + Console.WriteLine("Constructed from Dictionary with comparer:"); + foreach (var kvp in dict4) + Console.WriteLine($" {kvp.Key}: {kvp.Value}"); +} diff --git a/src/libraries/System.Collections/samples/System/Collections/Generic/SortedDictionary.samples.json b/src/libraries/System.Collections/samples/System/Collections/Generic/SortedDictionary.samples.json new file mode 100644 index 00000000000000..a157bd4dcf17a5 --- /dev/null +++ b/src/libraries/System.Collections/samples/System/Collections/Generic/SortedDictionary.samples.json @@ -0,0 +1,207 @@ +{ + "T:System.Collections.Generic.SortedDictionary`2": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in a SortedDictionary", + "primary": true + }, + "M:System.Collections.Generic.SortedDictionary`2.#ctor": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "Constructors", + "title": "Creating a SortedDictionary with various constructors", + "primary": true + }, + "M:System.Collections.Generic.SortedDictionary`2.#ctor(System.Collections.Generic.IComparer{`0})": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "Constructors", + "title": "Creating a SortedDictionary with a custom comparer" + }, + "M:System.Collections.Generic.SortedDictionary`2.#ctor(System.Collections.Generic.IDictionary{`0,`1})": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "Constructors", + "title": "Creating a SortedDictionary from an existing dictionary" + }, + "M:System.Collections.Generic.SortedDictionary`2.#ctor(System.Collections.Generic.IDictionary{`0,`1},System.Collections.Generic.IComparer{`0})": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "Constructors", + "title": "Creating a SortedDictionary from a dictionary with a comparer" + }, + "M:System.Collections.Generic.SortedDictionary`2.Add(`0,`1)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding items to a SortedDictionary" + }, + "M:System.Collections.Generic.SortedDictionary`2.Clear": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "RemoveAndClear", + "title": "Clearing all items from a SortedDictionary", + "primary": true + }, + "P:System.Collections.Generic.SortedDictionary`2.Comparer": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "Constructors", + "title": "Accessing the comparer of a SortedDictionary" + }, + "M:System.Collections.Generic.SortedDictionary`2.ContainsKey(`0)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Checking if a SortedDictionary contains a key" + }, + "M:System.Collections.Generic.SortedDictionary`2.ContainsValue(`1)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Checking if a SortedDictionary contains a value" + }, + "M:System.Collections.Generic.SortedDictionary`2.CopyTo(System.Collections.Generic.KeyValuePair{`0,`1}[],System.Int32)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "CopyToArray", + "title": "Copying SortedDictionary entries to an array", + "primary": true + }, + "P:System.Collections.Generic.SortedDictionary`2.Count": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Getting the count of items in a SortedDictionary" + }, + "M:System.Collections.Generic.SortedDictionary`2.GetEnumerator": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Enumerating key-value pairs in a SortedDictionary", + "primary": true + }, + "P:System.Collections.Generic.SortedDictionary`2.Item(`0)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Accessing items by key in a SortedDictionary" + }, + "P:System.Collections.Generic.SortedDictionary`2.Keys": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Getting the keys of a SortedDictionary" + }, + "M:System.Collections.Generic.SortedDictionary`2.Remove(`0)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "RemoveAndClear", + "title": "Removing an item from a SortedDictionary" + }, + "M:System.Collections.Generic.SortedDictionary`2.TryGetValue(`0,`1@)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Trying to get a value from a SortedDictionary" + }, + "P:System.Collections.Generic.SortedDictionary`2.Values": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Getting the values of a SortedDictionary" + }, + "M:System.Collections.Generic.SortedDictionary`2.System#Collections#Generic#ICollection>#Add(System.Collections.Generic.KeyValuePair{`0,`1})": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding items to a SortedDictionary" + }, + "M:System.Collections.Generic.SortedDictionary`2.System#Collections#Generic#ICollection>#Contains(System.Collections.Generic.KeyValuePair{`0,`1})": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Checking if a SortedDictionary contains a key-value pair" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#Generic#ICollection>#IsReadOnly": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Checking if a SortedDictionary is read-only" + }, + "M:System.Collections.Generic.SortedDictionary`2.System#Collections#Generic#ICollection>#Remove(System.Collections.Generic.KeyValuePair{`0,`1})": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "RemoveAndClear", + "title": "Removing a key-value pair from a SortedDictionary" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#Generic#IDictionary#Keys": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Getting keys via IDictionary interface" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#Generic#IDictionary#Values": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Getting values via IDictionary interface" + }, + "M:System.Collections.Generic.SortedDictionary`2.System#Collections#Generic#IEnumerable>#GetEnumerator": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Enumerating via IEnumerable interface" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#Generic#IReadOnlyDictionary#Keys": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Getting keys via IReadOnlyDictionary interface" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#Generic#IReadOnlyDictionary#Values": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Getting values via IReadOnlyDictionary interface" + }, + "M:System.Collections.Generic.SortedDictionary`2.System#Collections#ICollection#CopyTo(System.Array,System.Int32)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "CopyToArray", + "title": "Copying SortedDictionary entries to an array" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#ICollection#IsSynchronized": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Checking synchronization support" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#ICollection#SyncRoot": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Accessing synchronization root" + }, + "M:System.Collections.Generic.SortedDictionary`2.System#Collections#IDictionary#Add(System.Object,System.Object)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding items via IDictionary interface" + }, + "M:System.Collections.Generic.SortedDictionary`2.System#Collections#IDictionary#Contains(System.Object)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Checking containment via IDictionary interface" + }, + "M:System.Collections.Generic.SortedDictionary`2.System#Collections#IDictionary#GetEnumerator": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Enumerating via IDictionary interface" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#IDictionary#IsFixedSize": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Checking if a SortedDictionary is fixed size" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#IDictionary#IsReadOnly": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Checking if a SortedDictionary is read-only via IDictionary" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#IDictionary#Item(System.Object)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Accessing items via IDictionary interface" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#IDictionary#Keys": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Getting keys via IDictionary interface" + }, + "M:System.Collections.Generic.SortedDictionary`2.System#Collections#IDictionary#Remove(System.Object)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "RemoveAndClear", + "title": "Removing an item via IDictionary interface" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#IDictionary#Values": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Getting values via IDictionary interface" + }, + "M:System.Collections.Generic.SortedDictionary`2.System#Collections#IEnumerable#GetEnumerator": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Enumerating via IEnumerable interface" + } +} diff --git a/src/libraries/System.Collections/samples/System/Collections/Generic/SortedList.Examples.cs b/src/libraries/System.Collections/samples/System/Collections/Generic/SortedList.Examples.cs new file mode 100644 index 00000000000000..1b7b9373d21cce --- /dev/null +++ b/src/libraries/System.Collections/samples/System/Collections/Generic/SortedList.Examples.cs @@ -0,0 +1,164 @@ +using System; +using System.Collections.Generic; + +AddAndAccess(); +RemoveAndClear(); +IterateKeysAndValues(); +IndexBasedAccess(); +CapacityAndTrimExcess(); +ConstructWithComparer(); + +void AddAndAccess() +{ + SortedList list = new SortedList(); + + list.Add("apple", 3); + list.Add("banana", 2); + list.Add("cherry", 5); + + // Elements are maintained in sorted key order. + Console.WriteLine($"Count: {list.Count}"); // Count: 3 + + // Access by key using the indexer. + Console.WriteLine($"banana: {list["banana"]}"); // banana: 2 + + // The indexer can also add or update entries. + list["date"] = 7; + list["banana"] = 10; + Console.WriteLine($"banana updated: {list["banana"]}"); // banana updated: 10 + + Console.WriteLine($"ContainsKey(\"cherry\"): {list.ContainsKey("cherry")}"); // ContainsKey("cherry"): True + Console.WriteLine($"ContainsValue(5): {list.ContainsValue(5)}"); // ContainsValue(5): True + + // TryGetValue avoids exceptions for missing keys. + if (list.TryGetValue("apple", out int value)) + { + Console.WriteLine($"apple: {value}"); // apple: 3 + } + + Console.WriteLine($"TryGetValue(\"fig\"): {list.TryGetValue("fig", out _)}"); // TryGetValue("fig"): False +} + +void RemoveAndClear() +{ + SortedList list = new SortedList + { + { 1, "one" }, + { 2, "two" }, + { 3, "three" }, + { 4, "four" }, + { 5, "five" } + }; + + // Remove by key returns true if the key was found. + Console.WriteLine($"Remove(3): {list.Remove(3)}"); // Remove(3): True + Console.WriteLine($"Remove(99): {list.Remove(99)}"); // Remove(99): False + + // RemoveAt removes by sorted index. + Console.WriteLine($"Before RemoveAt(0): key={list.Keys[0]}"); // Before RemoveAt(0): key=1 + list.RemoveAt(0); + Console.WriteLine($"After RemoveAt(0): key={list.Keys[0]}"); // After RemoveAt(0): key=2 + + Console.WriteLine($"Count before Clear: {list.Count}"); // Count before Clear: 3 + list.Clear(); + Console.WriteLine($"Count after Clear: {list.Count}"); // Count after Clear: 0 +} + +void IterateKeysAndValues() +{ + SortedList list = new SortedList + { + { "alpha", 1.1 }, + { "beta", 2.2 }, + { "gamma", 3.3 } + }; + + // Iterate keys. + Console.Write("Keys: "); + foreach (string key in list.Keys) + { + Console.Write($"{key} "); + } + Console.WriteLine(); // Keys: alpha beta gamma + + // Iterate values. + Console.Write("Values: "); + foreach (double val in list.Values) + { + Console.Write($"{val} "); + } + Console.WriteLine(); // Values: 1.1 2.2 3.3 + + // Iterate key-value pairs using the enumerator (foreach). + foreach (KeyValuePair kvp in list) + { + Console.WriteLine($" {kvp.Key} = {kvp.Value}"); + } +} + +void IndexBasedAccess() +{ + SortedList list = new SortedList + { + { "cat", 4 }, + { "ant", 6 }, + { "dog", 2 }, + { "bat", 8 } + }; + + // IndexOfKey returns the zero-based sorted index, or -1 if not found. + Console.WriteLine($"IndexOfKey(\"cat\"): {list.IndexOfKey("cat")}"); // IndexOfKey("cat"): 2 + Console.WriteLine($"IndexOfKey(\"fox\"): {list.IndexOfKey("fox")}"); // IndexOfKey("fox"): -1 + + // IndexOfValue returns the index of the first occurrence, or -1. + Console.WriteLine($"IndexOfValue(8): {list.IndexOfValue(8)}"); // IndexOfValue(8): 1 + + // GetKeyAtIndex / GetValueAtIndex retrieve by sorted position. + Console.WriteLine($"GetKeyAtIndex(0): {list.GetKeyAtIndex(0)}"); // GetKeyAtIndex(0): ant + Console.WriteLine($"GetValueAtIndex(0): {list.GetValueAtIndex(0)}"); // GetValueAtIndex(0): 6 + + // SetValueAtIndex updates the value at a sorted position. + list.SetValueAtIndex(0, 100); + Console.WriteLine($"After SetValueAtIndex(0, 100): {list.GetValueAtIndex(0)}"); // After SetValueAtIndex(0, 100): 100 +} + +void CapacityAndTrimExcess() +{ + // Construct with an initial capacity. + SortedList list = new SortedList(100); + Console.WriteLine($"Initial Capacity: {list.Capacity}"); // Initial Capacity: 100 + + list.Add(1, "one"); + list.Add(2, "two"); + list.Add(3, "three"); + Console.WriteLine($"Count: {list.Count}"); // Count: 3 + Console.WriteLine($"Capacity: {list.Capacity}"); // Capacity: 100 + + // TrimExcess reduces capacity to match the count. + list.TrimExcess(); + Console.WriteLine($"Capacity after TrimExcess: {list.Capacity}"); // Capacity after TrimExcess: 3 +} + +void ConstructWithComparer() +{ + // Use a case-insensitive comparer for string keys. + SortedList list = new SortedList(StringComparer.OrdinalIgnoreCase); + + list.Add("Apple", 1); + list.Add("banana", 2); + + // "apple" matches "Apple" because the comparer ignores case. + Console.WriteLine($"ContainsKey(\"apple\"): {list.ContainsKey("apple")}"); // ContainsKey("apple"): True + Console.WriteLine($"Comparer: {list.Comparer}"); // Comparer: System.OrdinalIgnoreCaseComparer + + // Construct from an existing dictionary. + Dictionary source = new Dictionary + { + { "x", 10 }, + { "y", 20 }, + { "z", 30 } + }; + SortedList fromDict = new SortedList(source); + Console.WriteLine($"fromDict Count: {fromDict.Count}"); // fromDict Count: 3 + Console.WriteLine($"First key: {fromDict.GetKeyAtIndex(0)}"); // First key: x +} diff --git a/src/libraries/System.Collections/samples/System/Collections/Generic/SortedList.samples.json b/src/libraries/System.Collections/samples/System/Collections/Generic/SortedList.samples.json new file mode 100644 index 00000000000000..dc34a4960f180c --- /dev/null +++ b/src/libraries/System.Collections/samples/System/Collections/Generic/SortedList.samples.json @@ -0,0 +1,138 @@ +{ + "T:System.Collections.Generic.SortedList`2": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in a SortedList", + "primary": true + }, + "M:System.Collections.Generic.SortedList`2.#ctor(System.Int32)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "CapacityAndTrimExcess", + "title": "Managing SortedList capacity", + "primary": true + }, + "M:System.Collections.Generic.SortedList`2.#ctor(System.Collections.Generic.IComparer{`0})": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "ConstructWithComparer", + "title": "Constructing a SortedList with a custom comparer", + "primary": true + }, + "M:System.Collections.Generic.SortedList`2.#ctor(System.Int32,System.Collections.Generic.IComparer{`0})": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "ConstructWithComparer", + "title": "Constructing a SortedList with a custom comparer" + }, + "M:System.Collections.Generic.SortedList`2.#ctor(System.Collections.Generic.IDictionary{`0,`1})": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "ConstructWithComparer", + "title": "Constructing a SortedList with a custom comparer" + }, + "M:System.Collections.Generic.SortedList`2.#ctor(System.Collections.Generic.IDictionary{`0,`1},System.Collections.Generic.IComparer{`0})": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "ConstructWithComparer", + "title": "Constructing a SortedList with a custom comparer" + }, + "M:System.Collections.Generic.SortedList`2.Add(`0,`1)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in a SortedList" + }, + "P:System.Collections.Generic.SortedList`2.Capacity": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "CapacityAndTrimExcess", + "title": "Managing SortedList capacity" + }, + "M:System.Collections.Generic.SortedList`2.Clear": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "RemoveAndClear", + "title": "Removing items and clearing a SortedList", + "primary": true + }, + "P:System.Collections.Generic.SortedList`2.Comparer": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "ConstructWithComparer", + "title": "Constructing a SortedList with a custom comparer" + }, + "M:System.Collections.Generic.SortedList`2.ContainsKey(`0)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in a SortedList" + }, + "M:System.Collections.Generic.SortedList`2.ContainsValue(`1)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in a SortedList" + }, + "P:System.Collections.Generic.SortedList`2.Count": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in a SortedList" + }, + "M:System.Collections.Generic.SortedList`2.GetEnumerator": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Iterating keys, values, and pairs in a SortedList", + "primary": true + }, + "M:System.Collections.Generic.SortedList`2.GetKeyAtIndex(System.Int32)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "IndexBasedAccess", + "title": "Accessing SortedList elements by index", + "primary": true + }, + "M:System.Collections.Generic.SortedList`2.GetValueAtIndex(System.Int32)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "IndexBasedAccess", + "title": "Accessing SortedList elements by index" + }, + "M:System.Collections.Generic.SortedList`2.IndexOfKey(`0)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "IndexBasedAccess", + "title": "Accessing SortedList elements by index" + }, + "M:System.Collections.Generic.SortedList`2.IndexOfValue(`1)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "IndexBasedAccess", + "title": "Accessing SortedList elements by index" + }, + "P:System.Collections.Generic.SortedList`2.Item(`0)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in a SortedList" + }, + "P:System.Collections.Generic.SortedList`2.Keys": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Iterating keys, values, and pairs in a SortedList" + }, + "M:System.Collections.Generic.SortedList`2.Remove(`0)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "RemoveAndClear", + "title": "Removing items and clearing a SortedList" + }, + "M:System.Collections.Generic.SortedList`2.RemoveAt(System.Int32)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "RemoveAndClear", + "title": "Removing items and clearing a SortedList" + }, + "M:System.Collections.Generic.SortedList`2.SetValueAtIndex(System.Int32,`1)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "IndexBasedAccess", + "title": "Accessing SortedList elements by index" + }, + "M:System.Collections.Generic.SortedList`2.TrimExcess": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "CapacityAndTrimExcess", + "title": "Managing SortedList capacity" + }, + "M:System.Collections.Generic.SortedList`2.TryGetValue(`0,`1@)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in a SortedList" + }, + "P:System.Collections.Generic.SortedList`2.Values": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Iterating keys, values, and pairs in a SortedList" + } +} diff --git a/src/libraries/System.Collections/samples/System/Collections/Generic/SortedSet.Examples.cs b/src/libraries/System.Collections/samples/System/Collections/Generic/SortedSet.Examples.cs new file mode 100644 index 00000000000000..a739c9065651a5 --- /dev/null +++ b/src/libraries/System.Collections/samples/System/Collections/Generic/SortedSet.Examples.cs @@ -0,0 +1,135 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +AddContainsRemoveClear(); +SetOperations(); +SetComparisons(); +RangeViews(); +RemoveWhereExample(); +CopyToExample(); +CustomComparerExample(); + +void AddContainsRemoveClear() +{ + SortedSet numbers = new SortedSet(); + + // Add returns true if the element was added, false if it was already present. + Console.WriteLine(numbers.Add(5)); // True + Console.WriteLine(numbers.Add(3)); // True + Console.WriteLine(numbers.Add(5)); // False (duplicate) + Console.WriteLine(numbers.Add(1)); // True + Console.WriteLine(numbers.Add(4)); // True + + // Elements are maintained in sorted order. + Console.WriteLine(string.Join(", ", numbers)); // 1, 3, 4, 5 + + Console.WriteLine($"Count: {numbers.Count}"); // Count: 4 + Console.WriteLine($"Contains 3: {numbers.Contains(3)}"); // Contains 3: True + + // Remove returns true if the element was found and removed. + Console.WriteLine($"Remove 3: {numbers.Remove(3)}"); // Remove 3: True + Console.WriteLine($"Remove 9: {numbers.Remove(9)}"); // Remove 9: False + + Console.WriteLine(string.Join(", ", numbers)); // 1, 4, 5 + + numbers.Clear(); + Console.WriteLine($"Count after Clear: {numbers.Count}"); // Count after Clear: 0 +} + +void SetOperations() +{ + SortedSet setA = new SortedSet { 1, 2, 3, 4, 5 }; + SortedSet setB = new SortedSet { 3, 4, 5, 6, 7 }; + + // UnionWith adds all elements from the other collection. + SortedSet union = new SortedSet(setA); + union.UnionWith(setB); + Console.WriteLine($"Union: {string.Join(", ", union)}"); // Union: 1, 2, 3, 4, 5, 6, 7 + + // IntersectWith keeps only elements present in both. + SortedSet intersect = new SortedSet(setA); + intersect.IntersectWith(setB); + Console.WriteLine($"Intersect: {string.Join(", ", intersect)}"); // Intersect: 3, 4, 5 + + // ExceptWith removes elements that are in the other collection. + SortedSet except = new SortedSet(setA); + except.ExceptWith(setB); + Console.WriteLine($"Except: {string.Join(", ", except)}"); // Except: 1, 2 + + // SymmetricExceptWith keeps elements in either set but not both. + SortedSet symExcept = new SortedSet(setA); + symExcept.SymmetricExceptWith(setB); + Console.WriteLine($"SymmetricExcept: {string.Join(", ", symExcept)}"); // SymmetricExcept: 1, 2, 6, 7 +} + +void SetComparisons() +{ + SortedSet all = new SortedSet { 1, 2, 3, 4, 5 }; + SortedSet subset = new SortedSet { 2, 3 }; + SortedSet other = new SortedSet { 8, 9 }; + + Console.WriteLine($"subset IsSubsetOf all: {subset.IsSubsetOf(all)}"); // True + Console.WriteLine($"subset IsProperSubsetOf all: {subset.IsProperSubsetOf(all)}"); // True + Console.WriteLine($"all IsSupersetOf subset: {all.IsSupersetOf(subset)}"); // True + Console.WriteLine($"all IsProperSupersetOf subset: {all.IsProperSupersetOf(subset)}"); // True + + Console.WriteLine($"subset Overlaps all: {subset.Overlaps(all)}"); // True + Console.WriteLine($"other Overlaps all: {other.Overlaps(all)}"); // False + + SortedSet copy = new SortedSet { 1, 2, 3, 4, 5 }; + Console.WriteLine($"all SetEquals copy: {all.SetEquals(copy)}"); // True +} + +void RangeViews() +{ + SortedSet numbers = new SortedSet { 10, 20, 30, 40, 50, 60, 70, 80 }; + + Console.WriteLine($"Min: {numbers.Min}"); // Min: 10 + Console.WriteLine($"Max: {numbers.Max}"); // Max: 80 + + // GetViewBetween returns a subset view including both bounds. + SortedSet view = numbers.GetViewBetween(30, 60); + Console.WriteLine($"View [30..60]: {string.Join(", ", view)}"); // View [30..60]: 30, 40, 50, 60 + + // Reverse enumerates elements in descending order. + Console.WriteLine($"Descending: {string.Join(", ", numbers.Reverse())}"); + // Descending: 80, 70, 60, 50, 40, 30, 20, 10 +} + +void RemoveWhereExample() +{ + SortedSet numbers = new SortedSet { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + + // RemoveWhere removes all elements matching a predicate and returns the count removed. + int removed = numbers.RemoveWhere(n => n % 2 == 0); + Console.WriteLine($"Removed {removed} even numbers"); // Removed 5 even numbers + Console.WriteLine(string.Join(", ", numbers)); // 1, 3, 5, 7, 9 +} + +void CopyToExample() +{ + SortedSet fruits = new SortedSet { "apple", "banana", "cherry", "date" }; + + string[] array = new string[fruits.Count]; + fruits.CopyTo(array); + Console.WriteLine(string.Join(", ", array)); // apple, banana, cherry, date + + // CopyTo with index and count copies a subset into a destination array. + string[] partial = new string[6]; + fruits.CopyTo(partial, 1, 2); + Console.WriteLine($"partial[1] = {partial[1]}, partial[2] = {partial[2]}"); // partial[1] = apple, partial[2] = banana +} + +void CustomComparerExample() +{ + // Use a custom comparer for case-insensitive string sorting. + SortedSet names = new SortedSet(StringComparer.OrdinalIgnoreCase) + { + "Alice", "bob", "CHARLIE" + }; + + Console.WriteLine($"Comparer: {names.Comparer}"); // Comparer: System.OrdinalIgnoreComparer + Console.WriteLine($"Contains 'BOB': {names.Contains("BOB")}"); // Contains 'BOB': True + Console.WriteLine(string.Join(", ", names)); // Alice, bob, CHARLIE +} diff --git a/src/libraries/System.Collections/samples/System/Collections/Generic/SortedSet.samples.json b/src/libraries/System.Collections/samples/System/Collections/Generic/SortedSet.samples.json new file mode 100644 index 00000000000000..b42515f592b0a7 --- /dev/null +++ b/src/libraries/System.Collections/samples/System/Collections/Generic/SortedSet.samples.json @@ -0,0 +1,148 @@ +{ + "T:System.Collections.Generic.SortedSet`1": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "AddContainsRemoveClear", + "title": "Adding, checking, and removing items from a SortedSet", + "primary": true + }, + "M:System.Collections.Generic.SortedSet`1.#ctor(System.Collections.Generic.IComparer{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "CustomComparerExample", + "title": "Using a SortedSet with a custom comparer", + "primary": true + }, + "M:System.Collections.Generic.SortedSet`1.#ctor(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "SetOperations", + "title": "Performing set operations on SortedSet collections", + "primary": true + }, + "M:System.Collections.Generic.SortedSet`1.Add(`0)": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "AddContainsRemoveClear", + "title": "Adding, checking, and removing items from a SortedSet" + }, + "M:System.Collections.Generic.SortedSet`1.Clear": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "AddContainsRemoveClear", + "title": "Adding, checking, and removing items from a SortedSet" + }, + "P:System.Collections.Generic.SortedSet`1.Comparer": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "CustomComparerExample", + "title": "Using a SortedSet with a custom comparer" + }, + "M:System.Collections.Generic.SortedSet`1.Contains(`0)": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "AddContainsRemoveClear", + "title": "Adding, checking, and removing items from a SortedSet" + }, + "M:System.Collections.Generic.SortedSet`1.CopyTo(`0[])": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "CopyToExample", + "title": "Copying a SortedSet to an array", + "primary": true + }, + "M:System.Collections.Generic.SortedSet`1.CopyTo(`0[],System.Int32)": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "CopyToExample", + "title": "Copying a SortedSet to an array" + }, + "M:System.Collections.Generic.SortedSet`1.CopyTo(`0[],System.Int32,System.Int32)": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "CopyToExample", + "title": "Copying a SortedSet to an array" + }, + "P:System.Collections.Generic.SortedSet`1.Count": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "AddContainsRemoveClear", + "title": "Adding, checking, and removing items from a SortedSet" + }, + "M:System.Collections.Generic.SortedSet`1.ExceptWith(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "SetOperations", + "title": "Performing set operations on SortedSet collections" + }, + "M:System.Collections.Generic.SortedSet`1.GetEnumerator": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "AddContainsRemoveClear", + "title": "Adding, checking, and removing items from a SortedSet" + }, + "M:System.Collections.Generic.SortedSet`1.GetViewBetween(`0,`0)": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "RangeViews", + "title": "Using range views, Min, Max, and Reverse", + "primary": true + }, + "M:System.Collections.Generic.SortedSet`1.IntersectWith(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "SetOperations", + "title": "Performing set operations on SortedSet collections" + }, + "M:System.Collections.Generic.SortedSet`1.IsProperSubsetOf(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "SetComparisons", + "title": "Comparing SortedSet collections", + "primary": true + }, + "M:System.Collections.Generic.SortedSet`1.IsProperSupersetOf(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "SetComparisons", + "title": "Comparing SortedSet collections" + }, + "M:System.Collections.Generic.SortedSet`1.IsSubsetOf(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "SetComparisons", + "title": "Comparing SortedSet collections" + }, + "M:System.Collections.Generic.SortedSet`1.IsSupersetOf(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "SetComparisons", + "title": "Comparing SortedSet collections" + }, + "P:System.Collections.Generic.SortedSet`1.Max": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "RangeViews", + "title": "Using range views, Min, Max, and Reverse" + }, + "P:System.Collections.Generic.SortedSet`1.Min": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "RangeViews", + "title": "Using range views, Min, Max, and Reverse" + }, + "M:System.Collections.Generic.SortedSet`1.Overlaps(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "SetComparisons", + "title": "Comparing SortedSet collections" + }, + "M:System.Collections.Generic.SortedSet`1.Remove(`0)": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "AddContainsRemoveClear", + "title": "Adding, checking, and removing items from a SortedSet" + }, + "M:System.Collections.Generic.SortedSet`1.RemoveWhere(System.Predicate{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "RemoveWhereExample", + "title": "Removing elements matching a predicate" + }, + "M:System.Collections.Generic.SortedSet`1.Reverse": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "RangeViews", + "title": "Using range views, Min, Max, and Reverse" + }, + "M:System.Collections.Generic.SortedSet`1.SetEquals(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "SetComparisons", + "title": "Comparing SortedSet collections" + }, + "M:System.Collections.Generic.SortedSet`1.SymmetricExceptWith(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "SetOperations", + "title": "Performing set operations on SortedSet collections" + }, + "M:System.Collections.Generic.SortedSet`1.UnionWith(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "SetOperations", + "title": "Performing set operations on SortedSet collections" + } +} diff --git a/src/libraries/System.Collections/samples/System/Collections/Generic/Stack.Examples.cs b/src/libraries/System.Collections/samples/System/Collections/Generic/Stack.Examples.cs new file mode 100644 index 00000000000000..95a63c2929c41f --- /dev/null +++ b/src/libraries/System.Collections/samples/System/Collections/Generic/Stack.Examples.cs @@ -0,0 +1,128 @@ +using System; +using System.Collections.Generic; + +PushAndPop(); +PeekExample(); +TryPeekAndTryPop(); +ContainsExample(); +CountAndClear(); +CopyToAndToArray(); +EnumerateStack(); +CapacityAndTrimExcess(); +ConstructFromCollection(); +EnsureCapacityExample(); + +Console.WriteLine("All examples passed."); +return 0; + +void PushAndPop() +{ + Stack stack = new(); + stack.Push("first"); + stack.Push("second"); + stack.Push("third"); + Console.WriteLine($"Popped: {stack.Pop()}"); // third + Console.WriteLine($"Popped: {stack.Pop()}"); // second + Console.WriteLine($"Count after pops: {stack.Count}"); // 1 +} + +void PeekExample() +{ + Stack stack = new(); + stack.Push(10); + stack.Push(20); + Console.WriteLine($"Peek: {stack.Peek()}"); // 20 + Console.WriteLine($"Count after peek: {stack.Count}"); // 2 +} + +void TryPeekAndTryPop() +{ + Stack stack = new(); + bool hasPeek = stack.TryPeek(out int peekResult); + Console.WriteLine($"TryPeek on empty: {hasPeek}"); // False + + stack.Push(42); + bool hasPopped = stack.TryPop(out int popResult); + Console.WriteLine($"TryPop: {hasPopped}, value: {popResult}"); // True, 42 + Console.WriteLine($"Count after TryPop: {stack.Count}"); // 0 +} + +void ContainsExample() +{ + Stack stack = new(); + stack.Push("apple"); + stack.Push("banana"); + Console.WriteLine($"Contains 'apple': {stack.Contains("apple")}"); // True + Console.WriteLine($"Contains 'cherry': {stack.Contains("cherry")}"); // False +} + +void CountAndClear() +{ + Stack stack = new(); + stack.Push(1); + stack.Push(2); + stack.Push(3); + Console.WriteLine($"Count: {stack.Count}"); // 3 + stack.Clear(); + Console.WriteLine($"Count after Clear: {stack.Count}"); // 0 +} + +void CopyToAndToArray() +{ + Stack stack = new(); + stack.Push("a"); + stack.Push("b"); + stack.Push("c"); + + string[] array = stack.ToArray(); + Console.WriteLine($"ToArray: [{string.Join(", ", array)}]"); // c, b, a + + string[] dest = new string[5]; + stack.CopyTo(dest, 1); + Console.WriteLine($"CopyTo at index 1: [{string.Join(", ", dest)}]"); +} + +void EnumerateStack() +{ + Stack stack = new(); + stack.Push(10); + stack.Push(20); + stack.Push(30); + + Console.Write("Enumerate: "); + foreach (int item in stack) + { + Console.Write($"{item} "); + } + Console.WriteLine(); // 30 20 10 +} + +void CapacityAndTrimExcess() +{ + Stack stack = new(); + for (int i = 0; i < 100; i++) + stack.Push(i); + for (int i = 0; i < 90; i++) + stack.Pop(); + + Console.WriteLine($"Count: {stack.Count}, Capacity before trim: {stack.Capacity}"); + stack.TrimExcess(); + Console.WriteLine($"Capacity after TrimExcess: {stack.Capacity}"); +} + +void ConstructFromCollection() +{ + List list = new() { "one", "two", "three" }; + Stack stack = new(list); + Console.WriteLine($"Top of stack: {stack.Peek()}"); // three + Console.WriteLine($"Count: {stack.Count}"); // 3 +} + +void EnsureCapacityExample() +{ + Stack stack = new(); + int newCapacity = stack.EnsureCapacity(50); + Console.WriteLine($"Capacity after EnsureCapacity(50): {newCapacity}"); + stack.TrimExcess(20); + Console.WriteLine($"Capacity after TrimExcess(20): {stack.Capacity}"); +} diff --git a/src/libraries/System.Collections/samples/System/Collections/Generic/Stack.samples.json b/src/libraries/System.Collections/samples/System/Collections/Generic/Stack.samples.json new file mode 100644 index 00000000000000..760f535c0a02f0 --- /dev/null +++ b/src/libraries/System.Collections/samples/System/Collections/Generic/Stack.samples.json @@ -0,0 +1,124 @@ +{ + "T:System.Collections.Generic.Stack`1": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "PushAndPop", + "title": "Pushing and popping items from a Stack", + "primary": true + }, + "M:System.Collections.Generic.Stack`1.#ctor(System.Int32)": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "EnsureCapacityExample", + "title": "Ensuring capacity and trimming a Stack", + "primary": true + }, + "M:System.Collections.Generic.Stack`1.#ctor(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "ConstructFromCollection", + "title": "Constructing a Stack from a collection" + }, + "M:System.Collections.Generic.Stack`1.Push(`0)": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "PushAndPop", + "title": "Pushing and popping items from a Stack" + }, + "M:System.Collections.Generic.Stack`1.Pop": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "PushAndPop", + "title": "Pushing and popping items from a Stack" + }, + "M:System.Collections.Generic.Stack`1.Peek": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "PeekExample", + "title": "Peeking at the top of a Stack" + }, + "M:System.Collections.Generic.Stack`1.TryPeek(`0@)": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "TryPeekAndTryPop", + "title": "Using TryPeek and TryPop on a Stack", + "primary": true + }, + "M:System.Collections.Generic.Stack`1.TryPop(`0@)": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "TryPeekAndTryPop", + "title": "Using TryPeek and TryPop on a Stack" + }, + "M:System.Collections.Generic.Stack`1.Contains(`0)": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "ContainsExample", + "title": "Checking if a Stack contains an item" + }, + "P:System.Collections.Generic.Stack`1.Count": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "CountAndClear", + "title": "Counting items and clearing a Stack", + "primary": true + }, + "M:System.Collections.Generic.Stack`1.Clear": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "CountAndClear", + "title": "Counting items and clearing a Stack" + }, + "M:System.Collections.Generic.Stack`1.CopyTo(`0[],System.Int32)": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "CopyToAndToArray", + "title": "Copying a Stack to an array", + "primary": true + }, + "M:System.Collections.Generic.Stack`1.ToArray": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "CopyToAndToArray", + "title": "Copying a Stack to an array" + }, + "M:System.Collections.Generic.Stack`1.GetEnumerator": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "EnumerateStack", + "title": "Enumerating items in a Stack", + "primary": true + }, + "P:System.Collections.Generic.Stack`1.Capacity": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "CapacityAndTrimExcess", + "title": "Managing Stack capacity", + "primary": true + }, + "M:System.Collections.Generic.Stack`1.TrimExcess": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "CapacityAndTrimExcess", + "title": "Managing Stack capacity" + }, + "M:System.Collections.Generic.Stack`1.TrimExcess(System.Int32)": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "EnsureCapacityExample", + "title": "Ensuring capacity and trimming a Stack" + }, + "M:System.Collections.Generic.Stack`1.EnsureCapacity(System.Int32)": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "EnsureCapacityExample", + "title": "Ensuring capacity and trimming a Stack" + }, + "M:System.Collections.Generic.Stack`1.System#Collections#Generic#IEnumerable#GetEnumerator": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "EnumerateStack", + "title": "Enumerating items in a Stack" + }, + "M:System.Collections.Generic.Stack`1.System#Collections#IEnumerable#GetEnumerator": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "EnumerateStack", + "title": "Enumerating items in a Stack" + }, + "M:System.Collections.Generic.Stack`1.System#Collections#ICollection#CopyTo(System.Array,System.Int32)": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "CopyToAndToArray", + "title": "Copying a Stack to an array" + }, + "P:System.Collections.Generic.Stack`1.System#Collections#ICollection#IsSynchronized": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "PushAndPop", + "title": "Pushing and popping items from a Stack" + }, + "P:System.Collections.Generic.Stack`1.System#Collections#ICollection#SyncRoot": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "PushAndPop", + "title": "Pushing and popping items from a Stack" + } +} diff --git a/src/libraries/System.Collections/samples/samples.json b/src/libraries/System.Collections/samples/samples.json new file mode 100644 index 00000000000000..5ca916eee300cf --- /dev/null +++ b/src/libraries/System.Collections/samples/samples.json @@ -0,0 +1,1260 @@ +{ + "T:System.Collections.Generic.LinkedList`1": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "AddNodes", + "title": "Adding nodes to a LinkedList", + "primary": true + }, + "M:System.Collections.Generic.LinkedList`1.#ctor": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "RemoveNodes", + "title": "Removing nodes from a LinkedList", + "primary": true + }, + "M:System.Collections.Generic.LinkedList`1.#ctor(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "RemoveNodes", + "title": "Removing nodes from a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.AddFirst(`0)": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "AddNodes", + "title": "Adding nodes to a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.AddFirst(System.Collections.Generic.LinkedListNode{`0})": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "AddNodes", + "title": "Adding nodes to a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.AddLast(`0)": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "AddNodes", + "title": "Adding nodes to a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.AddLast(System.Collections.Generic.LinkedListNode{`0})": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "AddNodes", + "title": "Adding nodes to a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.AddAfter(System.Collections.Generic.LinkedListNode{`0},`0)": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "AddNodes", + "title": "Adding nodes to a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.AddAfter(System.Collections.Generic.LinkedListNode{`0},System.Collections.Generic.LinkedListNode{`0})": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "AddNodes", + "title": "Adding nodes to a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.AddBefore(System.Collections.Generic.LinkedListNode{`0},`0)": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "AddNodes", + "title": "Adding nodes to a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.AddBefore(System.Collections.Generic.LinkedListNode{`0},System.Collections.Generic.LinkedListNode{`0})": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "AddNodes", + "title": "Adding nodes to a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.Remove(`0)": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "RemoveNodes", + "title": "Removing nodes from a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.Remove(System.Collections.Generic.LinkedListNode{`0})": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "RemoveNodes", + "title": "Removing nodes from a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.RemoveFirst": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "RemoveNodes", + "title": "Removing nodes from a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.RemoveLast": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "RemoveNodes", + "title": "Removing nodes from a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.Clear": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "RemoveNodes", + "title": "Removing nodes from a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.Find(`0)": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "FindNodes", + "title": "Finding nodes in a LinkedList", + "primary": true + }, + "M:System.Collections.Generic.LinkedList`1.FindLast(`0)": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "FindNodes", + "title": "Finding nodes in a LinkedList" + }, + "M:System.Collections.Generic.LinkedList`1.Contains(`0)": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "FindNodes", + "title": "Finding nodes in a LinkedList" + }, + "P:System.Collections.Generic.LinkedList`1.First": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "NavigateNodes", + "title": "Navigating LinkedListNode properties", + "primary": true + }, + "P:System.Collections.Generic.LinkedList`1.Last": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "NavigateNodes", + "title": "Navigating LinkedListNode properties" + }, + "P:System.Collections.Generic.LinkedList`1.Count": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "NavigateNodes", + "title": "Navigating LinkedListNode properties" + }, + "M:System.Collections.Generic.LinkedList`1.CopyTo(`0[],System.Int32)": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "CopyToArray", + "title": "Copying a LinkedList to an array", + "primary": true + }, + "M:System.Collections.Generic.LinkedList`1.GetEnumerator": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "AddNodes", + "title": "Adding nodes to a LinkedList" + }, + "T:System.Collections.Generic.LinkedListNode`1": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "NavigateNodes", + "title": "Navigating LinkedListNode properties" + }, + "M:System.Collections.Generic.LinkedListNode`1.#ctor(`0)": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "NavigateNodes", + "title": "Navigating LinkedListNode properties" + }, + "P:System.Collections.Generic.LinkedListNode`1.Value": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "NavigateNodes", + "title": "Navigating LinkedListNode properties" + }, + "P:System.Collections.Generic.LinkedListNode`1.Next": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "NavigateNodes", + "title": "Navigating LinkedListNode properties" + }, + "P:System.Collections.Generic.LinkedListNode`1.Previous": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "NavigateNodes", + "title": "Navigating LinkedListNode properties" + }, + "P:System.Collections.Generic.LinkedListNode`1.List": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "NavigateNodes", + "title": "Navigating LinkedListNode properties" + }, + "P:System.Collections.Generic.LinkedListNode`1.ValueRef": { + "file": "System/Collections/Generic/LinkedList.Examples.cs", + "method": "NavigateNodes", + "title": "Navigating LinkedListNode properties" + }, + "T:System.Collections.Generic.OrderedDictionary`2": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary", + "primary": true + }, + "M:System.Collections.Generic.OrderedDictionary`2.#ctor": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.#ctor(System.Int32)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "ConstructFromCollection", + "title": "Constructing an OrderedDictionary from collections", + "primary": true + }, + "M:System.Collections.Generic.OrderedDictionary`2.#ctor(System.Collections.Generic.IEqualityComparer{`0})": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "ConstructFromCollection", + "title": "Constructing an OrderedDictionary from collections" + }, + "M:System.Collections.Generic.OrderedDictionary`2.#ctor(System.Int32,System.Collections.Generic.IEqualityComparer{`0})": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "ConstructFromCollection", + "title": "Constructing an OrderedDictionary from collections" + }, + "M:System.Collections.Generic.OrderedDictionary`2.#ctor(System.Collections.Generic.IDictionary{`0,`1})": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "ConstructFromCollection", + "title": "Constructing an OrderedDictionary from collections" + }, + "M:System.Collections.Generic.OrderedDictionary`2.#ctor(System.Collections.Generic.IDictionary{`0,`1},System.Collections.Generic.IEqualityComparer{`0})": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "ConstructFromCollection", + "title": "Constructing an OrderedDictionary from collections" + }, + "M:System.Collections.Generic.OrderedDictionary`2.#ctor(System.Collections.Generic.IEnumerable{System.Collections.Generic.KeyValuePair{`0,`1}})": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "ConstructFromCollection", + "title": "Constructing an OrderedDictionary from collections" + }, + "M:System.Collections.Generic.OrderedDictionary`2.#ctor(System.Collections.Generic.IEnumerable{System.Collections.Generic.KeyValuePair{`0,`1}},System.Collections.Generic.IEqualityComparer{`0})": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "ConstructFromCollection", + "title": "Constructing an OrderedDictionary from collections" + }, + "M:System.Collections.Generic.OrderedDictionary`2.Add(`0,`1)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.Item(`0)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.TryGetValue(`0,`1@)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.ContainsKey(`0)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.ContainsValue(`1)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.Count": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.GetAt(System.Int32)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "IndexBasedAccess", + "title": "Index-based access in an OrderedDictionary", + "primary": true + }, + "M:System.Collections.Generic.OrderedDictionary`2.SetAt(System.Int32,`1)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "IndexBasedAccess", + "title": "Index-based access in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.SetAt(System.Int32,`0,`1)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "IndexBasedAccess", + "title": "Index-based access in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.IndexOf(`0)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "IndexBasedAccess", + "title": "Index-based access in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.RemoveAt(System.Int32)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "IndexBasedAccess", + "title": "Index-based access in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.Insert(System.Int32,`0,`1)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "InsertAndRemove", + "title": "Inserting and removing items in an OrderedDictionary", + "primary": true + }, + "M:System.Collections.Generic.OrderedDictionary`2.Remove(`0)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "InsertAndRemove", + "title": "Inserting and removing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.Remove(`0,`1@)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "InsertAndRemove", + "title": "Inserting and removing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.Clear": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "InsertAndRemove", + "title": "Inserting and removing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.Keys": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary", + "primary": true + }, + "P:System.Collections.Generic.OrderedDictionary`2.Values": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.GetEnumerator": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.TryAdd(`0,`1)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "TryAddAndTryGetValue", + "title": "Using TryAdd and TryGetValue with an OrderedDictionary", + "primary": true + }, + "M:System.Collections.Generic.OrderedDictionary`2.TryAdd(`0,`1,System.Int32@)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "TryAddAndTryGetValue", + "title": "Using TryAdd and TryGetValue with an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.TryGetValue(`0,`1@,System.Int32@)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "TryAddAndTryGetValue", + "title": "Using TryAdd and TryGetValue with an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.Capacity": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "CapacityManagement", + "title": "Managing capacity of an OrderedDictionary", + "primary": true + }, + "M:System.Collections.Generic.OrderedDictionary`2.EnsureCapacity(System.Int32)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "CapacityManagement", + "title": "Managing capacity of an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.TrimExcess": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "CapacityManagement", + "title": "Managing capacity of an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.TrimExcess(System.Int32)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "CapacityManagement", + "title": "Managing capacity of an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.Comparer": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "CapacityManagement", + "title": "Managing capacity of an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#ICollection>#Add(System.Collections.Generic.KeyValuePair{`0,`1})": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#ICollection>#Contains(System.Collections.Generic.KeyValuePair{`0,`1})": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#ICollection>#CopyTo(System.Collections.Generic.KeyValuePair{`0,`1}[],System.Int32)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#ICollection>#IsReadOnly": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#ICollection>#Remove(System.Collections.Generic.KeyValuePair{`0,`1})": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "InsertAndRemove", + "title": "Inserting and removing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#IDictionary#Keys": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#IDictionary#Values": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#IEnumerable>#GetEnumerator": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#IList>#IndexOf(System.Collections.Generic.KeyValuePair{`0,`1})": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "IndexBasedAccess", + "title": "Index-based access in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#IList>#Insert(System.Int32,System.Collections.Generic.KeyValuePair{`0,`1})": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "InsertAndRemove", + "title": "Inserting and removing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#IList>#Item(System.Int32)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "IndexBasedAccess", + "title": "Index-based access in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#IReadOnlyDictionary#Keys": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#IReadOnlyDictionary#Values": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#Generic#IReadOnlyList>#Item(System.Int32)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "IndexBasedAccess", + "title": "Index-based access in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#ICollection#CopyTo(System.Array,System.Int32)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#ICollection#IsSynchronized": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#ICollection#SyncRoot": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#IDictionary#Add(System.Object,System.Object)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#IDictionary#Contains(System.Object)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#IDictionary#GetEnumerator": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#IDictionary#IsFixedSize": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#IDictionary#IsReadOnly": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#IDictionary#Item(System.Object)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#IDictionary#Keys": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#IDictionary#Remove(System.Object)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "InsertAndRemove", + "title": "Inserting and removing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#IDictionary#Values": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#IEnumerable#GetEnumerator": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "KeysValuesAndEnumerate", + "title": "Enumerating keys, values, and entries in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#IList#Add(System.Object)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#IList#Contains(System.Object)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#IList#IndexOf(System.Object)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "IndexBasedAccess", + "title": "Index-based access in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#IList#Insert(System.Int32,System.Object)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "InsertAndRemove", + "title": "Inserting and removing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#IList#IsFixedSize": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#IList#IsReadOnly": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in an OrderedDictionary" + }, + "P:System.Collections.Generic.OrderedDictionary`2.System#Collections#IList#Item(System.Int32)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "IndexBasedAccess", + "title": "Index-based access in an OrderedDictionary" + }, + "M:System.Collections.Generic.OrderedDictionary`2.System#Collections#IList#Remove(System.Object)": { + "file": "System/Collections/Generic/OrderedDictionary.Examples.cs", + "method": "InsertAndRemove", + "title": "Inserting and removing items in an OrderedDictionary" + }, + "T:System.Collections.Generic.PriorityQueue`2": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Enqueuing and dequeuing items by priority", + "primary": true + }, + "M:System.Collections.Generic.PriorityQueue`2.#ctor": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Enqueuing and dequeuing items by priority" + }, + "M:System.Collections.Generic.PriorityQueue`2.#ctor(System.Collections.Generic.IComparer{`1})": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Enqueuing and dequeuing items by priority" + }, + "M:System.Collections.Generic.PriorityQueue`2.#ctor(System.Collections.Generic.IEnumerable{System.ValueTuple{`0,`1}})": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueRangeDemo", + "title": "Initializing and enqueuing ranges of items", + "primary": true + }, + "M:System.Collections.Generic.PriorityQueue`2.#ctor(System.Int32)": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnsureCapacityAndTrimExcess", + "title": "Managing priority queue capacity", + "primary": true + }, + "M:System.Collections.Generic.PriorityQueue`2.#ctor(System.Collections.Generic.IEnumerable{System.ValueTuple{`0,`1}},System.Collections.Generic.IComparer{`1})": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueRangeDemo", + "title": "Initializing and enqueuing ranges of items" + }, + "M:System.Collections.Generic.PriorityQueue`2.#ctor(System.Int32,System.Collections.Generic.IComparer{`1})": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnsureCapacityAndTrimExcess", + "title": "Managing priority queue capacity" + }, + "P:System.Collections.Generic.PriorityQueue`2.Capacity": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnsureCapacityAndTrimExcess", + "title": "Managing priority queue capacity" + }, + "M:System.Collections.Generic.PriorityQueue`2.Clear": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Enqueuing and dequeuing items by priority" + }, + "P:System.Collections.Generic.PriorityQueue`2.Comparer": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Enqueuing and dequeuing items by priority" + }, + "P:System.Collections.Generic.PriorityQueue`2.Count": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Enqueuing and dequeuing items by priority" + }, + "M:System.Collections.Generic.PriorityQueue`2.Dequeue": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Enqueuing and dequeuing items by priority" + }, + "M:System.Collections.Generic.PriorityQueue`2.DequeueEnqueue(`0,`1)": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueDequeueAndDequeueEnqueue", + "title": "Using EnqueueDequeue and DequeueEnqueue", + "primary": true + }, + "M:System.Collections.Generic.PriorityQueue`2.Enqueue(`0,`1)": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Enqueuing and dequeuing items by priority" + }, + "M:System.Collections.Generic.PriorityQueue`2.EnqueueDequeue(`0,`1)": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueDequeueAndDequeueEnqueue", + "title": "Using EnqueueDequeue and DequeueEnqueue" + }, + "M:System.Collections.Generic.PriorityQueue`2.EnqueueRange(System.Collections.Generic.IEnumerable{System.ValueTuple{`0,`1}})": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueRangeDemo", + "title": "Initializing and enqueuing ranges of items" + }, + "M:System.Collections.Generic.PriorityQueue`2.EnqueueRange(System.Collections.Generic.IEnumerable{`0},`1)": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueRangeDemo", + "title": "Initializing and enqueuing ranges of items" + }, + "M:System.Collections.Generic.PriorityQueue`2.EnsureCapacity(System.Int32)": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnsureCapacityAndTrimExcess", + "title": "Managing priority queue capacity" + }, + "M:System.Collections.Generic.PriorityQueue`2.Peek": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Enqueuing and dequeuing items by priority" + }, + "M:System.Collections.Generic.PriorityQueue`2.Remove(`0,`0@,`1@,System.Collections.Generic.IEqualityComparer{`0})": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Enqueuing and dequeuing items by priority" + }, + "M:System.Collections.Generic.PriorityQueue`2.TrimExcess": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnsureCapacityAndTrimExcess", + "title": "Managing priority queue capacity" + }, + "M:System.Collections.Generic.PriorityQueue`2.TryDequeue(`0@,`1@)": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Enqueuing and dequeuing items by priority" + }, + "M:System.Collections.Generic.PriorityQueue`2.TryPeek(`0@,`1@)": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Enqueuing and dequeuing items by priority" + }, + "P:System.Collections.Generic.PriorityQueue`2.UnorderedItems": { + "file": "System/Collections/Generic/PriorityQueue.Examples.cs", + "method": "EnqueueRangeDemo", + "title": "Initializing and enqueuing ranges of items" + }, + "T:System.Collections.Generic.SortedDictionary`2": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in a SortedDictionary" + }, + "M:System.Collections.Generic.SortedDictionary`2.#ctor": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "Constructors", + "title": "Creating a SortedDictionary with various constructors", + "primary": true + }, + "M:System.Collections.Generic.SortedDictionary`2.#ctor(System.Collections.Generic.IComparer{`0})": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "Constructors", + "title": "Creating a SortedDictionary with a custom comparer" + }, + "M:System.Collections.Generic.SortedDictionary`2.#ctor(System.Collections.Generic.IDictionary{`0,`1})": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "Constructors", + "title": "Creating a SortedDictionary from an existing dictionary" + }, + "M:System.Collections.Generic.SortedDictionary`2.#ctor(System.Collections.Generic.IDictionary{`0,`1},System.Collections.Generic.IComparer{`0})": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "Constructors", + "title": "Creating a SortedDictionary from a dictionary with a comparer" + }, + "M:System.Collections.Generic.SortedDictionary`2.Add(`0,`1)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding items to a SortedDictionary" + }, + "M:System.Collections.Generic.SortedDictionary`2.Clear": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "RemoveAndClear", + "title": "Clearing all items from a SortedDictionary", + "primary": true + }, + "P:System.Collections.Generic.SortedDictionary`2.Comparer": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "Constructors", + "title": "Accessing the comparer of a SortedDictionary" + }, + "M:System.Collections.Generic.SortedDictionary`2.ContainsKey(`0)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Checking if a SortedDictionary contains a key" + }, + "M:System.Collections.Generic.SortedDictionary`2.ContainsValue(`1)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Checking if a SortedDictionary contains a value" + }, + "M:System.Collections.Generic.SortedDictionary`2.CopyTo(System.Collections.Generic.KeyValuePair{`0,`1}[],System.Int32)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "CopyToArray", + "title": "Copying SortedDictionary entries to an array" + }, + "P:System.Collections.Generic.SortedDictionary`2.Count": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Getting the count of items in a SortedDictionary" + }, + "M:System.Collections.Generic.SortedDictionary`2.GetEnumerator": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Enumerating key-value pairs in a SortedDictionary", + "primary": true + }, + "P:System.Collections.Generic.SortedDictionary`2.Item(`0)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Accessing items by key in a SortedDictionary" + }, + "P:System.Collections.Generic.SortedDictionary`2.Keys": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Getting the keys of a SortedDictionary" + }, + "M:System.Collections.Generic.SortedDictionary`2.Remove(`0)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "RemoveAndClear", + "title": "Removing an item from a SortedDictionary" + }, + "M:System.Collections.Generic.SortedDictionary`2.TryGetValue(`0,`1@)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Trying to get a value from a SortedDictionary" + }, + "P:System.Collections.Generic.SortedDictionary`2.Values": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Getting the values of a SortedDictionary" + }, + "M:System.Collections.Generic.SortedDictionary`2.System#Collections#Generic#ICollection>#Add(System.Collections.Generic.KeyValuePair{`0,`1})": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding items to a SortedDictionary" + }, + "M:System.Collections.Generic.SortedDictionary`2.System#Collections#Generic#ICollection>#Contains(System.Collections.Generic.KeyValuePair{`0,`1})": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Checking if a SortedDictionary contains a key-value pair" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#Generic#ICollection>#IsReadOnly": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Checking if a SortedDictionary is read-only" + }, + "M:System.Collections.Generic.SortedDictionary`2.System#Collections#Generic#ICollection>#Remove(System.Collections.Generic.KeyValuePair{`0,`1})": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "RemoveAndClear", + "title": "Removing a key-value pair from a SortedDictionary" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#Generic#IDictionary#Keys": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Getting keys via IDictionary interface" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#Generic#IDictionary#Values": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Getting values via IDictionary interface" + }, + "M:System.Collections.Generic.SortedDictionary`2.System#Collections#Generic#IEnumerable>#GetEnumerator": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Enumerating via IEnumerable interface" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#Generic#IReadOnlyDictionary#Keys": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Getting keys via IReadOnlyDictionary interface" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#Generic#IReadOnlyDictionary#Values": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Getting values via IReadOnlyDictionary interface" + }, + "M:System.Collections.Generic.SortedDictionary`2.System#Collections#ICollection#CopyTo(System.Array,System.Int32)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "CopyToArray", + "title": "Copying SortedDictionary entries to an array" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#ICollection#IsSynchronized": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Checking synchronization support" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#ICollection#SyncRoot": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Accessing synchronization root" + }, + "M:System.Collections.Generic.SortedDictionary`2.System#Collections#IDictionary#Add(System.Object,System.Object)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Adding items via IDictionary interface" + }, + "M:System.Collections.Generic.SortedDictionary`2.System#Collections#IDictionary#Contains(System.Object)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Checking containment via IDictionary interface" + }, + "M:System.Collections.Generic.SortedDictionary`2.System#Collections#IDictionary#GetEnumerator": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Enumerating via IDictionary interface" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#IDictionary#IsFixedSize": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Checking if a SortedDictionary is fixed size" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#IDictionary#IsReadOnly": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Checking if a SortedDictionary is read-only via IDictionary" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#IDictionary#Item(System.Object)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Accessing items via IDictionary interface" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#IDictionary#Keys": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Getting keys via IDictionary interface" + }, + "M:System.Collections.Generic.SortedDictionary`2.System#Collections#IDictionary#Remove(System.Object)": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "RemoveAndClear", + "title": "Removing an item via IDictionary interface" + }, + "P:System.Collections.Generic.SortedDictionary`2.System#Collections#IDictionary#Values": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Getting values via IDictionary interface" + }, + "M:System.Collections.Generic.SortedDictionary`2.System#Collections#IEnumerable#GetEnumerator": { + "file": "System/Collections/Generic/SortedDictionary.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Enumerating via IEnumerable interface" + }, + "T:System.Collections.Generic.SortedList`2": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in a SortedList" + }, + "M:System.Collections.Generic.SortedList`2.#ctor": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in a SortedList" + }, + "M:System.Collections.Generic.SortedList`2.#ctor(System.Int32)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "CapacityAndTrimExcess", + "title": "Managing SortedList capacity", + "primary": true + }, + "M:System.Collections.Generic.SortedList`2.#ctor(System.Collections.Generic.IComparer{`0})": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "ConstructWithComparer", + "title": "Constructing a SortedList with a custom comparer", + "primary": true + }, + "M:System.Collections.Generic.SortedList`2.#ctor(System.Int32,System.Collections.Generic.IComparer{`0})": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "ConstructWithComparer", + "title": "Constructing a SortedList with a custom comparer" + }, + "M:System.Collections.Generic.SortedList`2.#ctor(System.Collections.Generic.IDictionary{`0,`1})": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "ConstructWithComparer", + "title": "Constructing a SortedList with a custom comparer" + }, + "M:System.Collections.Generic.SortedList`2.#ctor(System.Collections.Generic.IDictionary{`0,`1},System.Collections.Generic.IComparer{`0})": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "ConstructWithComparer", + "title": "Constructing a SortedList with a custom comparer" + }, + "M:System.Collections.Generic.SortedList`2.Add(`0,`1)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in a SortedList" + }, + "P:System.Collections.Generic.SortedList`2.Capacity": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "CapacityAndTrimExcess", + "title": "Managing SortedList capacity" + }, + "M:System.Collections.Generic.SortedList`2.Clear": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "RemoveAndClear", + "title": "Removing items and clearing a SortedList" + }, + "P:System.Collections.Generic.SortedList`2.Comparer": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "ConstructWithComparer", + "title": "Constructing a SortedList with a custom comparer" + }, + "M:System.Collections.Generic.SortedList`2.ContainsKey(`0)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in a SortedList" + }, + "M:System.Collections.Generic.SortedList`2.ContainsValue(`1)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in a SortedList" + }, + "P:System.Collections.Generic.SortedList`2.Count": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in a SortedList" + }, + "M:System.Collections.Generic.SortedList`2.GetEnumerator": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Iterating keys, values, and pairs in a SortedList" + }, + "M:System.Collections.Generic.SortedList`2.GetKeyAtIndex(System.Int32)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "IndexBasedAccess", + "title": "Accessing SortedList elements by index" + }, + "M:System.Collections.Generic.SortedList`2.GetValueAtIndex(System.Int32)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "IndexBasedAccess", + "title": "Accessing SortedList elements by index" + }, + "M:System.Collections.Generic.SortedList`2.IndexOfKey(`0)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "IndexBasedAccess", + "title": "Accessing SortedList elements by index" + }, + "M:System.Collections.Generic.SortedList`2.IndexOfValue(`1)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "IndexBasedAccess", + "title": "Accessing SortedList elements by index" + }, + "P:System.Collections.Generic.SortedList`2.Item(`0)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in a SortedList" + }, + "P:System.Collections.Generic.SortedList`2.Keys": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Iterating keys, values, and pairs in a SortedList" + }, + "M:System.Collections.Generic.SortedList`2.Remove(`0)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "RemoveAndClear", + "title": "Removing items and clearing a SortedList" + }, + "M:System.Collections.Generic.SortedList`2.RemoveAt(System.Int32)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "RemoveAndClear", + "title": "Removing items and clearing a SortedList" + }, + "M:System.Collections.Generic.SortedList`2.SetValueAtIndex(System.Int32,`1)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "IndexBasedAccess", + "title": "Accessing SortedList elements by index" + }, + "M:System.Collections.Generic.SortedList`2.TrimExcess": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "CapacityAndTrimExcess", + "title": "Managing SortedList capacity" + }, + "M:System.Collections.Generic.SortedList`2.TryGetValue(`0,`1@)": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "AddAndAccess", + "title": "Adding and accessing items in a SortedList" + }, + "P:System.Collections.Generic.SortedList`2.Values": { + "file": "System/Collections/Generic/SortedList.Examples.cs", + "method": "IterateKeysAndValues", + "title": "Iterating keys, values, and pairs in a SortedList" + }, + "T:System.Collections.Generic.SortedSet`1": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "AddContainsRemoveClear", + "title": "Adding, checking, and removing items from a SortedSet", + "primary": true + }, + "M:System.Collections.Generic.SortedSet`1.#ctor": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "AddContainsRemoveClear", + "title": "Adding, checking, and removing items from a SortedSet" + }, + "M:System.Collections.Generic.SortedSet`1.#ctor(System.Collections.Generic.IComparer{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "CustomComparerExample", + "title": "Using a SortedSet with a custom comparer", + "primary": true + }, + "M:System.Collections.Generic.SortedSet`1.#ctor(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "SetOperations", + "title": "Performing set operations on SortedSet collections", + "primary": true + }, + "M:System.Collections.Generic.SortedSet`1.Add(`0)": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "AddContainsRemoveClear", + "title": "Adding, checking, and removing items from a SortedSet" + }, + "M:System.Collections.Generic.SortedSet`1.Clear": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "AddContainsRemoveClear", + "title": "Adding, checking, and removing items from a SortedSet" + }, + "P:System.Collections.Generic.SortedSet`1.Comparer": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "CustomComparerExample", + "title": "Using a SortedSet with a custom comparer" + }, + "M:System.Collections.Generic.SortedSet`1.Contains(`0)": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "AddContainsRemoveClear", + "title": "Adding, checking, and removing items from a SortedSet" + }, + "M:System.Collections.Generic.SortedSet`1.CopyTo(`0[])": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "CopyToExample", + "title": "Copying a SortedSet to an array", + "primary": true + }, + "M:System.Collections.Generic.SortedSet`1.CopyTo(`0[],System.Int32)": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "CopyToExample", + "title": "Copying a SortedSet to an array" + }, + "M:System.Collections.Generic.SortedSet`1.CopyTo(`0[],System.Int32,System.Int32)": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "CopyToExample", + "title": "Copying a SortedSet to an array" + }, + "P:System.Collections.Generic.SortedSet`1.Count": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "AddContainsRemoveClear", + "title": "Adding, checking, and removing items from a SortedSet" + }, + "M:System.Collections.Generic.SortedSet`1.ExceptWith(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "SetOperations", + "title": "Performing set operations on SortedSet collections" + }, + "M:System.Collections.Generic.SortedSet`1.GetEnumerator": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "AddContainsRemoveClear", + "title": "Adding, checking, and removing items from a SortedSet" + }, + "M:System.Collections.Generic.SortedSet`1.GetViewBetween(`0,`0)": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "RangeViews", + "title": "Using range views, Min, Max, and Reverse", + "primary": true + }, + "M:System.Collections.Generic.SortedSet`1.IntersectWith(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "SetOperations", + "title": "Performing set operations on SortedSet collections" + }, + "M:System.Collections.Generic.SortedSet`1.IsProperSubsetOf(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "SetComparisons", + "title": "Comparing SortedSet collections", + "primary": true + }, + "M:System.Collections.Generic.SortedSet`1.IsProperSupersetOf(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "SetComparisons", + "title": "Comparing SortedSet collections" + }, + "M:System.Collections.Generic.SortedSet`1.IsSubsetOf(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "SetComparisons", + "title": "Comparing SortedSet collections" + }, + "M:System.Collections.Generic.SortedSet`1.IsSupersetOf(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "SetComparisons", + "title": "Comparing SortedSet collections" + }, + "P:System.Collections.Generic.SortedSet`1.Max": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "RangeViews", + "title": "Using range views, Min, Max, and Reverse" + }, + "P:System.Collections.Generic.SortedSet`1.Min": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "RangeViews", + "title": "Using range views, Min, Max, and Reverse" + }, + "M:System.Collections.Generic.SortedSet`1.Overlaps(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "SetComparisons", + "title": "Comparing SortedSet collections" + }, + "M:System.Collections.Generic.SortedSet`1.Remove(`0)": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "AddContainsRemoveClear", + "title": "Adding, checking, and removing items from a SortedSet" + }, + "M:System.Collections.Generic.SortedSet`1.RemoveWhere(System.Predicate{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "RemoveWhereExample", + "title": "Removing elements matching a predicate" + }, + "M:System.Collections.Generic.SortedSet`1.Reverse": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "RangeViews", + "title": "Using range views, Min, Max, and Reverse" + }, + "M:System.Collections.Generic.SortedSet`1.SetEquals(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "SetComparisons", + "title": "Comparing SortedSet collections" + }, + "M:System.Collections.Generic.SortedSet`1.SymmetricExceptWith(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "SetOperations", + "title": "Performing set operations on SortedSet collections" + }, + "M:System.Collections.Generic.SortedSet`1.UnionWith(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/SortedSet.Examples.cs", + "method": "SetOperations", + "title": "Performing set operations on SortedSet collections" + }, + "T:System.Collections.Generic.Stack`1": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "PushAndPop", + "title": "Pushing and popping items from a Stack", + "primary": true + }, + "M:System.Collections.Generic.Stack`1.#ctor": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "PushAndPop", + "title": "Pushing and popping items from a Stack" + }, + "M:System.Collections.Generic.Stack`1.#ctor(System.Int32)": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "EnsureCapacityExample", + "title": "Ensuring capacity and trimming a Stack", + "primary": true + }, + "M:System.Collections.Generic.Stack`1.#ctor(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "ConstructFromCollection", + "title": "Constructing a Stack from a collection" + }, + "M:System.Collections.Generic.Stack`1.Push(`0)": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "PushAndPop", + "title": "Pushing and popping items from a Stack" + }, + "M:System.Collections.Generic.Stack`1.Pop": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "PushAndPop", + "title": "Pushing and popping items from a Stack" + }, + "M:System.Collections.Generic.Stack`1.Peek": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "PeekExample", + "title": "Peeking at the top of a Stack" + }, + "M:System.Collections.Generic.Stack`1.TryPeek(`0@)": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "TryPeekAndTryPop", + "title": "Using TryPeek and TryPop on a Stack", + "primary": true + }, + "M:System.Collections.Generic.Stack`1.TryPop(`0@)": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "TryPeekAndTryPop", + "title": "Using TryPeek and TryPop on a Stack" + }, + "M:System.Collections.Generic.Stack`1.Contains(`0)": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "ContainsExample", + "title": "Checking if a Stack contains an item" + }, + "P:System.Collections.Generic.Stack`1.Count": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "CountAndClear", + "title": "Counting items and clearing a Stack", + "primary": true + }, + "M:System.Collections.Generic.Stack`1.Clear": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "CountAndClear", + "title": "Counting items and clearing a Stack" + }, + "M:System.Collections.Generic.Stack`1.CopyTo(`0[],System.Int32)": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "CopyToAndToArray", + "title": "Copying a Stack to an array", + "primary": true + }, + "M:System.Collections.Generic.Stack`1.ToArray": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "CopyToAndToArray", + "title": "Copying a Stack to an array" + }, + "M:System.Collections.Generic.Stack`1.GetEnumerator": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "EnumerateStack", + "title": "Enumerating items in a Stack", + "primary": true + }, + "P:System.Collections.Generic.Stack`1.Capacity": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "CapacityAndTrimExcess", + "title": "Managing Stack capacity" + }, + "M:System.Collections.Generic.Stack`1.TrimExcess": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "CapacityAndTrimExcess", + "title": "Managing Stack capacity" + }, + "M:System.Collections.Generic.Stack`1.TrimExcess(System.Int32)": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "EnsureCapacityExample", + "title": "Ensuring capacity and trimming a Stack" + }, + "M:System.Collections.Generic.Stack`1.EnsureCapacity(System.Int32)": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "EnsureCapacityExample", + "title": "Ensuring capacity and trimming a Stack" + }, + "M:System.Collections.Generic.Stack`1.System#Collections#Generic#IEnumerable#GetEnumerator": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "EnumerateStack", + "title": "Enumerating items in a Stack" + }, + "M:System.Collections.Generic.Stack`1.System#Collections#IEnumerable#GetEnumerator": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "EnumerateStack", + "title": "Enumerating items in a Stack" + }, + "M:System.Collections.Generic.Stack`1.System#Collections#ICollection#CopyTo(System.Array,System.Int32)": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "CopyToAndToArray", + "title": "Copying a Stack to an array" + }, + "P:System.Collections.Generic.Stack`1.System#Collections#ICollection#IsSynchronized": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "PushAndPop", + "title": "Pushing and popping items from a Stack" + }, + "P:System.Collections.Generic.Stack`1.System#Collections#ICollection#SyncRoot": { + "file": "System/Collections/Generic/Stack.Examples.cs", + "method": "PushAndPop", + "title": "Pushing and popping items from a Stack" + } +} diff --git a/src/libraries/System.Private.CoreLib/samples/Directory.Build.props b/src/libraries/System.Private.CoreLib/samples/Directory.Build.props new file mode 100644 index 00000000000000..d541fc3a2c6e17 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/samples/Directory.Build.props @@ -0,0 +1,11 @@ + + + + net11.0 + false + false + false + false + false + + diff --git a/src/libraries/System.Private.CoreLib/samples/Directory.Build.targets b/src/libraries/System.Private.CoreLib/samples/Directory.Build.targets new file mode 100644 index 00000000000000..8c119d5413b585 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/samples/Directory.Build.targets @@ -0,0 +1,2 @@ + + diff --git a/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/Dictionary.Examples.cs b/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/Dictionary.Examples.cs new file mode 100644 index 00000000000000..4b59fd377d6f0c --- /dev/null +++ b/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/Dictionary.Examples.cs @@ -0,0 +1,151 @@ +using System; +using System.Collections.Generic; + +AddAndAccess(); +RemoveItems(); +BulkOperations(); +CapacityOperations(); +TryOperations(); +Console.WriteLine("All examples passed."); +return 0; + +void AddAndAccess() +{ + // Create a dictionary using collection initializer syntax. + Dictionary ages = new() + { + ["Alice"] = 30, + ["Bob"] = 25 + }; + + // Add inserts a new key/value pair. + ages.Add("Charlie", 35); + Console.WriteLine($"Count: {ages.Count}"); + // Output: Count: 3 + + // The indexer retrieves values by key. + Console.WriteLine($"Bob's age: {ages["Bob"]}"); + // Output: Bob's age: 25 + + // TryGetValue safely retrieves a value without throwing. + if (ages.TryGetValue("Alice", out int aliceAge)) + { + Console.WriteLine($"Alice's age: {aliceAge}"); + // Output: Alice's age: 30 + } + + // ContainsKey checks for a key. + Console.WriteLine($"Has 'Charlie': {ages.ContainsKey("Charlie")}"); + // Output: Has 'Charlie': True + + // ContainsValue checks for a value. + Console.WriteLine($"Has age 25: {ages.ContainsValue(25)}"); + // Output: Has age 25: True + + // The indexer can also update an existing entry. + ages["Bob"] = 26; + Console.WriteLine($"Bob's updated age: {ages["Bob"]}"); + // Output: Bob's updated age: 26 +} + +void RemoveItems() +{ + Dictionary scores = new() + { + ["Math"] = 95.0, + ["Science"] = 88.5, + ["History"] = 72.0 + }; + + // Remove deletes an entry by key and returns true if found. + bool removed = scores.Remove("History"); + Console.WriteLine($"Removed 'History': {removed}"); + // Output: Removed 'History': True + Console.WriteLine($"Count after Remove: {scores.Count}"); + // Output: Count after Remove: 2 + + // Remove overload also returns the removed value. + if (scores.Remove("Math", out double mathScore)) + { + Console.WriteLine($"Removed 'Math' with score: {mathScore}"); + // Output: Removed 'Math' with score: 95 + } + + // Clear removes all entries. + scores.Clear(); + Console.WriteLine($"Count after Clear: {scores.Count}"); + // Output: Count after Clear: 0 +} + +void BulkOperations() +{ + Dictionary capitals = new() + { + ["France"] = "Paris", + ["Japan"] = "Tokyo", + ["Brazil"] = "Brasília" + }; + + // Keys returns all keys in the dictionary. + Console.WriteLine($"Keys: {string.Join(", ", capitals.Keys)}"); + + // Values returns all values in the dictionary. + Console.WriteLine($"Values: {string.Join(", ", capitals.Values)}"); + + // Enumerate key/value pairs with foreach (uses GetEnumerator). + foreach (KeyValuePair kvp in capitals) + { + Console.WriteLine($" {kvp.Key} -> {kvp.Value}"); + } + + Console.WriteLine($"Count: {capitals.Count}"); + // Output: Count: 3 +} + +void CapacityOperations() +{ + Dictionary dict = new(); + + // EnsureCapacity pre-allocates internal storage. + int capacity = dict.EnsureCapacity(100); + Console.WriteLine($"EnsureCapacity(100) returned: {capacity}"); + + for (int i = 0; i < 10; i++) + { + dict.Add(i, $"item-{i}"); + } + Console.WriteLine($"Count: {dict.Count}, Capacity: {dict.Capacity}"); + + // TrimExcess(int) trims capacity to hold a specified number of entries. + dict.TrimExcess(20); + Console.WriteLine($"Capacity after TrimExcess(20): {dict.Capacity}"); + + // TrimExcess without arguments trims capacity to match the current count. + dict.TrimExcess(); + Console.WriteLine($"Capacity after TrimExcess: {dict.Capacity}"); +} + +void TryOperations() +{ + Dictionary inventory = new() + { + ["Apples"] = 5, + ["Bananas"] = 12 + }; + + // TryAdd adds only if the key does not already exist. + bool added = inventory.TryAdd("Cherries", 8); + Console.WriteLine($"TryAdd 'Cherries': {added}"); + // Output: TryAdd 'Cherries': True + + bool duplicate = inventory.TryAdd("Apples", 99); + Console.WriteLine($"TryAdd 'Apples' (duplicate): {duplicate}"); + // Output: TryAdd 'Apples' (duplicate): False + Console.WriteLine($"Apples count unchanged: {inventory["Apples"]}"); + // Output: Apples count unchanged: 5 + + // TryGetValue returns false for missing keys. + bool found = inventory.TryGetValue("Grapes", out int grapes); + Console.WriteLine($"TryGetValue 'Grapes': found={found}, value={grapes}"); + // Output: TryGetValue 'Grapes': found=False, value=0 +} diff --git a/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/Dictionary.samples.json b/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/Dictionary.samples.json new file mode 100644 index 00000000000000..14965eef74188f --- /dev/null +++ b/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/Dictionary.samples.json @@ -0,0 +1,96 @@ +{ + "T:System.Collections.Generic.Dictionary`2": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Dictionary AddAndAccess", + "primary": true + }, + "M:System.Collections.Generic.Dictionary`2.Add(`0,`1)": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Dictionary AddAndAccess" + }, + "P:System.Collections.Generic.Dictionary`2.Item(`0)": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Dictionary AddAndAccess" + }, + "M:System.Collections.Generic.Dictionary`2.TryGetValue(`0,`1@)": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Dictionary AddAndAccess" + }, + "M:System.Collections.Generic.Dictionary`2.ContainsKey(`0)": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Dictionary AddAndAccess" + }, + "M:System.Collections.Generic.Dictionary`2.ContainsValue(`1)": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Dictionary AddAndAccess" + }, + "P:System.Collections.Generic.Dictionary`2.Count": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Dictionary AddAndAccess" + }, + "M:System.Collections.Generic.Dictionary`2.Remove(`0)": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "RemoveItems", + "title": "Dictionary RemoveItems", + "primary": true + }, + "M:System.Collections.Generic.Dictionary`2.Remove(`0,`1@)": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "RemoveItems", + "title": "Dictionary RemoveItems" + }, + "M:System.Collections.Generic.Dictionary`2.Clear": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "RemoveItems", + "title": "Dictionary RemoveItems" + }, + "P:System.Collections.Generic.Dictionary`2.Keys": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "BulkOperations", + "title": "Dictionary BulkOperations", + "primary": true + }, + "P:System.Collections.Generic.Dictionary`2.Values": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "BulkOperations", + "title": "Dictionary BulkOperations" + }, + "M:System.Collections.Generic.Dictionary`2.GetEnumerator": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "BulkOperations", + "title": "Dictionary BulkOperations" + }, + "P:System.Collections.Generic.Dictionary`2.Capacity": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "CapacityOperations", + "title": "Dictionary CapacityOperations", + "primary": true + }, + "M:System.Collections.Generic.Dictionary`2.EnsureCapacity(System.Int32)": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "CapacityOperations", + "title": "Dictionary CapacityOperations" + }, + "M:System.Collections.Generic.Dictionary`2.TrimExcess": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "CapacityOperations", + "title": "Dictionary CapacityOperations" + }, + "M:System.Collections.Generic.Dictionary`2.TrimExcess(System.Int32)": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "CapacityOperations", + "title": "Dictionary CapacityOperations" + }, + "M:System.Collections.Generic.Dictionary`2.TryAdd(`0,`1)": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "TryOperations", + "title": "Dictionary TryOperations" + } +} diff --git a/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/HashSet.Examples.cs b/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/HashSet.Examples.cs new file mode 100644 index 00000000000000..5f2def2e33f099 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/HashSet.Examples.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections.Generic; + +AddAndContains(); +SetOperations(); +SetComparisons(); +Capacity(); + +Console.WriteLine("All examples passed."); +return 0; + +void AddAndContains() +{ + HashSet names = ["Alice", "Bob", "Charlie"]; + + Console.WriteLine($"Count: {names.Count}"); + // Output: Count: 3 + + bool added = names.Add("Diana"); + Console.WriteLine($"Added Diana: {added}"); + // Output: Added Diana: True + + added = names.Add("Alice"); + Console.WriteLine($"Added Alice again: {added}"); + // Output: Added Alice again: False + + Console.WriteLine($"Contains Bob: {names.Contains("Bob")}"); + // Output: Contains Bob: True + + bool removed = names.Remove("Bob"); + Console.WriteLine($"Removed Bob: {removed}"); + // Output: Removed Bob: True + + Console.WriteLine($"Count after remove: {names.Count}"); + // Output: Count after remove: 3 + + names.Clear(); + Console.WriteLine($"Count after clear: {names.Count}"); + // Output: Count after clear: 0 +} + +void SetOperations() +{ + HashSet evens = [2, 4, 6, 8]; + HashSet odds = [1, 3, 5, 7]; + HashSet primes = [2, 3, 5, 7]; + + // UnionWith adds all elements from the other collection + HashSet union = new(evens); + union.UnionWith(odds); + Console.WriteLine($"Union: {string.Join(", ", union)}"); + // Output includes all of: 1, 2, 3, 4, 5, 6, 7, 8 + + // IntersectWith keeps only elements present in both + HashSet intersect = new(odds); + intersect.IntersectWith(primes); + Console.WriteLine($"Odds ∩ Primes: {string.Join(", ", intersect)}"); + // Output includes: 3, 5, 7 + + // ExceptWith removes elements found in the other collection + HashSet except = new(primes); + except.ExceptWith(odds); + Console.WriteLine($"Primes - Odds: {string.Join(", ", except)}"); + // Output: Primes - Odds: 2 + + // SymmetricExceptWith keeps elements in either set but not both + HashSet symmetric = new(evens); + symmetric.SymmetricExceptWith(primes); + Console.WriteLine($"Evens △ Primes: {string.Join(", ", symmetric)}"); + // Output includes: 3, 4, 5, 6, 7, 8 (but not 2) +} + +void SetComparisons() +{ + HashSet all = [1, 2, 3, 4, 5]; + HashSet subset = [2, 3]; + HashSet same = [1, 2, 3, 4, 5]; + HashSet other = [4, 5, 6]; + + Console.WriteLine($"subset ⊂ all (proper): {subset.IsProperSubsetOf(all)}"); + // Output: subset ⊂ all (proper): True + + Console.WriteLine($"subset ⊆ all: {subset.IsSubsetOf(all)}"); + // Output: subset ⊆ all: True + + Console.WriteLine($"all ⊃ subset (proper): {all.IsProperSupersetOf(subset)}"); + // Output: all ⊃ subset (proper): True + + Console.WriteLine($"all ⊇ subset: {all.IsSupersetOf(subset)}"); + // Output: all ⊇ subset: True + + Console.WriteLine($"all == same: {all.SetEquals(same)}"); + // Output: all == same: True + + Console.WriteLine($"all overlaps other: {all.Overlaps(other)}"); + // Output: all overlaps other: True + + // A set is a subset of itself but not a proper subset + Console.WriteLine($"all ⊆ same: {all.IsSubsetOf(same)}"); + // Output: all ⊆ same: True + Console.WriteLine($"all ⊂ same (proper): {all.IsProperSubsetOf(same)}"); + // Output: all ⊂ same (proper): False +} + +void Capacity() +{ + HashSet numbers = new(); + + // Reserve space for at least 100 elements + int capacity = numbers.EnsureCapacity(100); + Console.WriteLine($"Capacity after EnsureCapacity(100): {capacity}"); + // Output: Capacity after EnsureCapacity(100): >= 100 + + numbers.Add(1); + numbers.Add(2); + numbers.Add(3); + + // TrimExcess reduces capacity to match the count + numbers.TrimExcess(); + Console.WriteLine($"Count: {numbers.Count}"); + // Output: Count: 3 +} diff --git a/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/HashSet.samples.json b/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/HashSet.samples.json new file mode 100644 index 00000000000000..c94cb564944c87 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/HashSet.samples.json @@ -0,0 +1,91 @@ +{ + "M:System.Collections.Generic.HashSet`1.Add(`0)": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "AddAndContains", + "title": "Adding, querying, removing, and clearing elements", + "primary": true + }, + "M:System.Collections.Generic.HashSet`1.Contains(`0)": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "AddAndContains", + "title": "Adding, querying, removing, and clearing elements" + }, + "M:System.Collections.Generic.HashSet`1.Remove(`0)": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "AddAndContains", + "title": "Adding, querying, removing, and clearing elements" + }, + "M:System.Collections.Generic.HashSet`1.Clear": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "AddAndContains", + "title": "Adding, querying, removing, and clearing elements" + }, + "P:System.Collections.Generic.HashSet`1.Count": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "AddAndContains", + "title": "Adding, querying, removing, and clearing elements" + }, + "M:System.Collections.Generic.HashSet`1.UnionWith(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "SetOperations", + "title": "Union, intersection, difference, and symmetric difference", + "primary": true + }, + "M:System.Collections.Generic.HashSet`1.IntersectWith(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "SetOperations", + "title": "Union, intersection, difference, and symmetric difference" + }, + "M:System.Collections.Generic.HashSet`1.ExceptWith(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "SetOperations", + "title": "Union, intersection, difference, and symmetric difference" + }, + "M:System.Collections.Generic.HashSet`1.SymmetricExceptWith(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "SetOperations", + "title": "Union, intersection, difference, and symmetric difference" + }, + "M:System.Collections.Generic.HashSet`1.IsSubsetOf(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "SetComparisons", + "title": "Subset, superset, overlap, and equality comparisons", + "primary": true + }, + "M:System.Collections.Generic.HashSet`1.IsSupersetOf(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "SetComparisons", + "title": "Subset, superset, overlap, and equality comparisons" + }, + "M:System.Collections.Generic.HashSet`1.IsProperSubsetOf(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "SetComparisons", + "title": "Subset, superset, overlap, and equality comparisons" + }, + "M:System.Collections.Generic.HashSet`1.IsProperSupersetOf(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "SetComparisons", + "title": "Subset, superset, overlap, and equality comparisons" + }, + "M:System.Collections.Generic.HashSet`1.Overlaps(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "SetComparisons", + "title": "Subset, superset, overlap, and equality comparisons" + }, + "M:System.Collections.Generic.HashSet`1.SetEquals(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "SetComparisons", + "title": "Subset, superset, overlap, and equality comparisons" + }, + "M:System.Collections.Generic.HashSet`1.EnsureCapacity(System.Int32)": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "Capacity", + "title": "Managing HashSet capacity", + "primary": true + }, + "M:System.Collections.Generic.HashSet`1.TrimExcess": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "Capacity", + "title": "Managing HashSet capacity" + } +} diff --git a/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/List.Examples.cs b/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/List.Examples.cs new file mode 100644 index 00000000000000..3c583444e39b2e --- /dev/null +++ b/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/List.Examples.cs @@ -0,0 +1,234 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; + +AddAndInsert(); +SearchItems(); +FindItems(); +RemoveItems(); +ConvertAndCopy(); +CapacityAndCount(); +Iterate(); +SortAndReverse(); +Indexer(); + +Console.WriteLine("All examples passed."); +return 0; + +void AddAndInsert() +{ + List names = ["Alice", "Bob"]; + names.Add("Charlie"); + Console.WriteLine(string.Join(", ", names)); + // Output: Alice, Bob, Charlie + + names.AddRange(new[] { "Diana", "Eve" }); + Console.WriteLine(string.Join(", ", names)); + // Output: Alice, Bob, Charlie, Diana, Eve + + names.Insert(1, "Zara"); + Console.WriteLine(string.Join(", ", names)); + // Output: Alice, Zara, Bob, Charlie, Diana, Eve + + names.InsertRange(3, new[] { "Frank", "Grace" }); + Console.WriteLine(string.Join(", ", names)); + // Output: Alice, Zara, Bob, Frank, Grace, Charlie, Diana, Eve +} + +void SearchItems() +{ + List numbers = [1, 3, 5, 7, 9, 11, 13]; + + // BinarySearch requires a sorted list + int index = numbers.BinarySearch(7); + Console.WriteLine($"BinarySearch(7): found at index {index}"); + // Output: BinarySearch(7): found at index 3 + + Console.WriteLine($"Contains(5): {numbers.Contains(5)}"); + // Output: Contains(5): True + + Console.WriteLine($"IndexOf(9): {numbers.IndexOf(9)}"); + // Output: IndexOf(9): 4 + + numbers.Add(3); + // numbers is now [1, 3, 5, 7, 9, 11, 13, 3] + Console.WriteLine($"LastIndexOf(3): {numbers.LastIndexOf(3)}"); + // Output: LastIndexOf(3): 7 + + Console.WriteLine($"Exists(x => x > 10): {numbers.Exists(x => x > 10)}"); + // Output: Exists(x => x > 10): True + + Console.WriteLine($"TrueForAll(x => x > 0): {numbers.TrueForAll(x => x > 0)}"); + // Output: TrueForAll(x => x > 0): True +} + +void FindItems() +{ + List fruits = ["apple", "banana", "cherry", "date", "elderberry", "banana"]; + + string? found = fruits.Find(f => f.StartsWith("ch")); + Console.WriteLine($"Find starts with 'ch': {found}"); + // Output: Find starts with 'ch': cherry + + string? last = fruits.FindLast(f => f.Contains("an")); + Console.WriteLine($"FindLast contains 'an': {last}"); + // Output: FindLast contains 'an': banana + + int idx = fruits.FindIndex(f => f.Length > 5); + Console.WriteLine($"FindIndex length > 5: {idx}"); + // Output: FindIndex length > 5: 1 + + int lastIdx = fruits.FindLastIndex(f => f.Length > 5); + Console.WriteLine($"FindLastIndex length > 5: {lastIdx}"); + // Output: FindLastIndex length > 5: 5 + + List allLong = fruits.FindAll(f => f.Length > 5); + Console.WriteLine($"FindAll length > 5: {string.Join(", ", allLong)}"); + // Output: FindAll length > 5: banana, cherry, elderberry, banana +} + +void RemoveItems() +{ + List numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + + numbers.Remove(5); + Console.WriteLine($"After Remove(5): {string.Join(", ", numbers)}"); + // Output: After Remove(5): 1, 2, 3, 4, 6, 7, 8, 9, 10 + + numbers.RemoveAt(0); + Console.WriteLine($"After RemoveAt(0): {string.Join(", ", numbers)}"); + // Output: After RemoveAt(0): 2, 3, 4, 6, 7, 8, 9, 10 + + numbers.RemoveRange(4, 2); + Console.WriteLine($"After RemoveRange(4, 2): {string.Join(", ", numbers)}"); + // Output: After RemoveRange(4, 2): 2, 3, 4, 6, 9, 10 + + int removed = numbers.RemoveAll(x => x % 3 == 0); + Console.WriteLine($"RemoveAll divisible by 3: removed {removed}, remaining: {string.Join(", ", numbers)}"); + // Output: RemoveAll divisible by 3: removed 3, remaining: 2, 4, 10 + + numbers.Clear(); + Console.WriteLine($"After Clear: count = {numbers.Count}"); + // Output: After Clear: count = 0 +} + +void ConvertAndCopy() +{ + List numbers = [1, 2, 3, 4, 5]; + + List strings = numbers.ConvertAll(n => n.ToString()); + Console.WriteLine($"ConvertAll: {string.Join(", ", strings)}"); + // Output: ConvertAll: 1, 2, 3, 4, 5 + + int[] array = numbers.ToArray(); + Console.WriteLine($"ToArray: {string.Join(", ", array)}"); + // Output: ToArray: 1, 2, 3, 4, 5 + + int[] dest = new int[5]; + numbers.CopyTo(dest); + Console.WriteLine($"CopyTo: {string.Join(", ", dest)}"); + // Output: CopyTo: 1, 2, 3, 4, 5 + + List range = numbers.GetRange(1, 3); + Console.WriteLine($"GetRange(1, 3): {string.Join(", ", range)}"); + // Output: GetRange(1, 3): 2, 3, 4 + + List slice = numbers.Slice(2, 2); + Console.WriteLine($"Slice(2, 2): {string.Join(", ", slice)}"); + // Output: Slice(2, 2): 3, 4 + + ReadOnlyCollection readOnly = numbers.AsReadOnly(); + Console.WriteLine($"AsReadOnly: count = {readOnly.Count}, is read-only = true"); + // Output: AsReadOnly: count = 5, is read-only = true +} + +void CapacityAndCount() +{ + List numbers = new List(); + Console.WriteLine($"Initial — Count: {numbers.Count}, Capacity: {numbers.Capacity}"); + // Output: Initial — Count: 0, Capacity: 0 + + numbers.EnsureCapacity(20); + Console.WriteLine($"After EnsureCapacity(20) — Capacity: {numbers.Capacity}"); + // Output: After EnsureCapacity(20) — Capacity: 20 + + for (int i = 0; i < 5; i++) + numbers.Add(i); + + Console.WriteLine($"After adding 5 items — Count: {numbers.Count}, Capacity: {numbers.Capacity}"); + // Output: After adding 5 items — Count: 5, Capacity: 20 + + numbers.TrimExcess(); + Console.WriteLine($"After TrimExcess — Count: {numbers.Count}, Capacity: {numbers.Capacity}"); + // Output: After TrimExcess — Count: 5, Capacity: 5 + + numbers.Capacity = 10; + Console.WriteLine($"After setting Capacity = 10 — Capacity: {numbers.Capacity}"); + // Output: After setting Capacity = 10 — Capacity: 10 +} + +void Iterate() +{ + List colors = ["red", "green", "blue"]; + + // Using ForEach with an Action + Console.Write("ForEach: "); + colors.ForEach(c => Console.Write($"{c} ")); + Console.WriteLine(); + // Output: ForEach: red green blue + + // Using GetEnumerator explicitly + Console.Write("Enumerator: "); + using (List.Enumerator enumerator = colors.GetEnumerator()) + { + while (enumerator.MoveNext()) + Console.Write($"{enumerator.Current} "); + } + Console.WriteLine(); + // Output: Enumerator: red green blue + + // Using foreach (the most common way) + Console.Write("foreach: "); + foreach (string color in colors) + Console.Write($"{color} "); + Console.WriteLine(); + // Output: foreach: red green blue +} + +void SortAndReverse() +{ + List names = ["Charlie", "Alice", "Eve", "Bob", "Diana"]; + + names.Sort(); + Console.WriteLine($"Sort(): {string.Join(", ", names)}"); + // Output: Sort(): Alice, Bob, Charlie, Diana, Eve + + names.Sort((a, b) => b.Length.CompareTo(a.Length)); + Console.WriteLine($"Sort by length desc: {string.Join(", ", names)}"); + // Output: Sort by length desc: Charlie, Diana, Alice, Bob, Eve + + names.Reverse(); + Console.WriteLine($"Reverse(): {string.Join(", ", names)}"); + // Output: Reverse(): Eve, Bob, Alice, Diana, Charlie + + List numbers = [5, 3, 1, 4, 2]; + numbers.Sort(1, 3, Comparer.Default); + Console.WriteLine($"Sort(1, 3, default): {string.Join(", ", numbers)}"); + // Output: Sort(1, 3, default): 5, 1, 3, 4, 2 + + numbers.Reverse(0, 3); + Console.WriteLine($"Reverse(0, 3): {string.Join(", ", numbers)}"); + // Output: Reverse(0, 3): 3, 1, 5, 4, 2 +} + +void Indexer() +{ + List animals = ["cat", "dog", "bird"]; + + Console.WriteLine($"animals[0]: {animals[0]}"); + // Output: animals[0]: cat + + animals[1] = "fish"; + Console.WriteLine($"After animals[1] = \"fish\": {string.Join(", ", animals)}"); + // Output: After animals[1] = "fish": cat, fish, bird +} diff --git a/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/List.samples.json b/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/List.samples.json new file mode 100644 index 00000000000000..a6d1f5373246bb --- /dev/null +++ b/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/List.samples.json @@ -0,0 +1,280 @@ +{ + "T:System.Collections.Generic.List`1": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "AddAndInsert", + "title": "Create a List and add items", + "primary": true + }, + "M:System.Collections.Generic.List`1.#ctor": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "CapacityAndCount", + "title": "Create lists and manage capacity", + "primary": true + }, + "M:System.Collections.Generic.List`1.#ctor(System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "CapacityAndCount", + "title": "Create a List with initial capacity" + }, + "M:System.Collections.Generic.List`1.Add(`0)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "AddAndInsert", + "title": "Add items to a List" + }, + "M:System.Collections.Generic.List`1.AddRange(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "AddAndInsert", + "title": "Add a range of items to a List" + }, + "M:System.Collections.Generic.List`1.AsReadOnly": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "ConvertAndCopy", + "title": "Create a read-only wrapper", + "primary": true + }, + "M:System.Collections.Generic.List`1.BinarySearch(System.Int32,System.Int32,`0,System.Collections.Generic.IComparer{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Binary search within a range", + "primary": true + }, + "M:System.Collections.Generic.List`1.BinarySearch(`0)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Binary search a sorted List" + }, + "M:System.Collections.Generic.List`1.BinarySearch(`0,System.Collections.Generic.IComparer{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Binary search with a comparer" + }, + "P:System.Collections.Generic.List`1.Capacity": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "CapacityAndCount", + "title": "Manage List capacity" + }, + "M:System.Collections.Generic.List`1.Clear": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "RemoveItems", + "title": "Clear all items from a List", + "primary": true + }, + "M:System.Collections.Generic.List`1.Contains(`0)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Check if a List contains an item" + }, + "M:System.Collections.Generic.List`1.ConvertAll``1(System.Converter{`0,``0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "ConvertAndCopy", + "title": "Convert all items in a List" + }, + "M:System.Collections.Generic.List`1.CopyTo(System.Int32,`0[],System.Int32,System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "ConvertAndCopy", + "title": "Copy a range of items to an array" + }, + "M:System.Collections.Generic.List`1.CopyTo(`0[])": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "ConvertAndCopy", + "title": "Copy List to an array" + }, + "M:System.Collections.Generic.List`1.CopyTo(`0[],System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "ConvertAndCopy", + "title": "Copy List to an array at an index" + }, + "P:System.Collections.Generic.List`1.Count": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "CapacityAndCount", + "title": "Get the number of items in a List" + }, + "M:System.Collections.Generic.List`1.EnsureCapacity(System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "CapacityAndCount", + "title": "Ensure minimum capacity" + }, + "M:System.Collections.Generic.List`1.Exists(System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Check if any item matches a predicate" + }, + "M:System.Collections.Generic.List`1.Find(System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "FindItems", + "title": "Find the first matching item", + "primary": true + }, + "M:System.Collections.Generic.List`1.FindAll(System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "FindItems", + "title": "Find all matching items" + }, + "M:System.Collections.Generic.List`1.FindIndex(System.Int32,System.Int32,System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "FindItems", + "title": "Find index within a range" + }, + "M:System.Collections.Generic.List`1.FindIndex(System.Int32,System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "FindItems", + "title": "Find index starting at an offset" + }, + "M:System.Collections.Generic.List`1.FindIndex(System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "FindItems", + "title": "Find the index of the first match" + }, + "M:System.Collections.Generic.List`1.FindLast(System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "FindItems", + "title": "Find the last matching item" + }, + "M:System.Collections.Generic.List`1.FindLastIndex(System.Int32,System.Int32,System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "FindItems", + "title": "Find last index within a range" + }, + "M:System.Collections.Generic.List`1.FindLastIndex(System.Int32,System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "FindItems", + "title": "Find last index up to an offset" + }, + "M:System.Collections.Generic.List`1.FindLastIndex(System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "FindItems", + "title": "Find the index of the last match" + }, + "M:System.Collections.Generic.List`1.ForEach(System.Action{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "Iterate", + "title": "Execute an action on each item", + "primary": true + }, + "M:System.Collections.Generic.List`1.GetEnumerator": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "Iterate", + "title": "Get an enumerator for the List" + }, + "M:System.Collections.Generic.List`1.GetRange(System.Int32,System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "ConvertAndCopy", + "title": "Get a range of items as a new List" + }, + "M:System.Collections.Generic.List`1.IndexOf(`0)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Find the index of an item" + }, + "M:System.Collections.Generic.List`1.IndexOf(`0,System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Find the index starting at an offset" + }, + "M:System.Collections.Generic.List`1.IndexOf(`0,System.Int32,System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Find the index within a range" + }, + "M:System.Collections.Generic.List`1.Insert(System.Int32,`0)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "AddAndInsert", + "title": "Insert an item at an index" + }, + "M:System.Collections.Generic.List`1.InsertRange(System.Int32,System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "AddAndInsert", + "title": "Insert a range of items at an index" + }, + "P:System.Collections.Generic.List`1.Item(System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "Indexer", + "title": "Access items by index" + }, + "M:System.Collections.Generic.List`1.LastIndexOf(`0)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Find the last index of an item" + }, + "M:System.Collections.Generic.List`1.LastIndexOf(`0,System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Find the last index up to an offset" + }, + "M:System.Collections.Generic.List`1.LastIndexOf(`0,System.Int32,System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Find the last index within a range" + }, + "M:System.Collections.Generic.List`1.Remove(`0)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "RemoveItems", + "title": "Remove the first occurrence of an item" + }, + "M:System.Collections.Generic.List`1.RemoveAll(System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "RemoveItems", + "title": "Remove all items matching a predicate" + }, + "M:System.Collections.Generic.List`1.RemoveAt(System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "RemoveItems", + "title": "Remove an item at an index" + }, + "M:System.Collections.Generic.List`1.RemoveRange(System.Int32,System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "RemoveItems", + "title": "Remove a range of items" + }, + "M:System.Collections.Generic.List`1.Reverse": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SortAndReverse", + "title": "Reverse the order of items", + "primary": true + }, + "M:System.Collections.Generic.List`1.Reverse(System.Int32,System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SortAndReverse", + "title": "Reverse a range of items" + }, + "M:System.Collections.Generic.List`1.Slice(System.Int32,System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "ConvertAndCopy", + "title": "Get a slice of items as a new List" + }, + "M:System.Collections.Generic.List`1.Sort": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SortAndReverse", + "title": "Sort items in default order" + }, + "M:System.Collections.Generic.List`1.Sort(System.Collections.Generic.IComparer{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SortAndReverse", + "title": "Sort items with a comparer" + }, + "M:System.Collections.Generic.List`1.Sort(System.Comparison{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SortAndReverse", + "title": "Sort items with a comparison delegate" + }, + "M:System.Collections.Generic.List`1.Sort(System.Int32,System.Int32,System.Collections.Generic.IComparer{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SortAndReverse", + "title": "Sort a range of items" + }, + "M:System.Collections.Generic.List`1.ToArray": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "ConvertAndCopy", + "title": "Convert a List to an array" + }, + "M:System.Collections.Generic.List`1.TrimExcess": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "CapacityAndCount", + "title": "Trim excess capacity" + }, + "M:System.Collections.Generic.List`1.TrueForAll(System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Check if all items match a predicate" + } +} diff --git a/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/Queue.Examples.cs b/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/Queue.Examples.cs new file mode 100644 index 00000000000000..72368ce1c4a073 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/Queue.Examples.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; + +EnqueueAndDequeue(); +BulkOperations(); +Capacity(); +Console.WriteLine("All examples passed."); +return 0; + +void EnqueueAndDequeue() +{ + Queue queue = new(); + + // Enqueue adds items to the back of the queue. + queue.Enqueue("apple"); + queue.Enqueue("banana"); + queue.Enqueue("cherry"); + Console.WriteLine($"Count after enqueuing 3 items: {queue.Count}"); + // Output: Count after enqueuing 3 items: 3 + + // Peek returns the front item without removing it. + Console.WriteLine($"Peek: {queue.Peek()}"); + // Output: Peek: apple + + // Dequeue removes and returns the front item. + Console.WriteLine($"Dequeue: {queue.Dequeue()}"); + // Output: Dequeue: apple + Console.WriteLine($"Count after dequeue: {queue.Count}"); + // Output: Count after dequeue: 2 + + // TryDequeue attempts to remove the front item safely. + if (queue.TryDequeue(out string? result)) + { + Console.WriteLine($"TryDequeue: {result}"); + // Output: TryDequeue: banana + } + + // TryPeek attempts to read the front item safely. + if (queue.TryPeek(out string? peeked)) + { + Console.WriteLine($"TryPeek: {peeked}"); + // Output: TryPeek: cherry + } + + // TryDequeue on an empty queue returns false. + queue.Dequeue(); // remove "cherry" + bool success = queue.TryDequeue(out _); + Console.WriteLine($"TryDequeue on empty queue: {success}"); + // Output: TryDequeue on empty queue: False +} + +void BulkOperations() +{ + Queue queue = new(); + queue.Enqueue(10); + queue.Enqueue(20); + queue.Enqueue(30); + queue.Enqueue(40); + + // Contains checks whether an item is in the queue. + Console.WriteLine($"Contains 20: {queue.Contains(20)}"); + // Output: Contains 20: True + Console.WriteLine($"Contains 99: {queue.Contains(99)}"); + // Output: Contains 99: False + + // ToArray copies the queue elements to a new array. + int[] array = queue.ToArray(); + Console.WriteLine($"ToArray: [{string.Join(", ", array)}]"); + // Output: ToArray: [10, 20, 30, 40] + + // CopyTo copies elements into an existing array at a given index. + int[] destination = new int[6]; + queue.CopyTo(destination, 2); + Console.WriteLine($"CopyTo: [{string.Join(", ", destination)}]"); + // Output: CopyTo: [0, 0, 10, 20, 30, 40] + + // Clear removes all items from the queue. + queue.Clear(); + Console.WriteLine($"Count after Clear: {queue.Count}"); + // Output: Count after Clear: 0 +} + +void Capacity() +{ + Queue queue = new(); + + // EnsureCapacity guarantees minimum internal storage. + int newCapacity = queue.EnsureCapacity(50); + Console.WriteLine($"EnsureCapacity(50) returned: {newCapacity}"); + // Output: EnsureCapacity(50) returned: 50 (or higher) + + for (int i = 0; i < 10; i++) + { + queue.Enqueue(i * 1.5); + } + Console.WriteLine($"Count: {queue.Count}, Capacity: {queue.Capacity}"); + + // TrimExcess reduces capacity to match the current count. + queue.TrimExcess(); + Console.WriteLine($"Capacity after TrimExcess: {queue.Capacity}"); + // Output: Capacity after TrimExcess: 10 +} diff --git a/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/Queue.samples.json b/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/Queue.samples.json new file mode 100644 index 00000000000000..4fccea62189ad6 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/samples/System/Collections/Generic/Queue.samples.json @@ -0,0 +1,80 @@ +{ + "T:System.Collections.Generic.Queue`1": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Queue EnqueueAndDequeue", + "primary": true + }, + "M:System.Collections.Generic.Queue`1.Enqueue(`0)": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Queue EnqueueAndDequeue" + }, + "M:System.Collections.Generic.Queue`1.Dequeue": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Queue EnqueueAndDequeue" + }, + "M:System.Collections.Generic.Queue`1.Peek": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Queue EnqueueAndDequeue" + }, + "M:System.Collections.Generic.Queue`1.TryDequeue(`0@)": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Queue EnqueueAndDequeue" + }, + "M:System.Collections.Generic.Queue`1.TryPeek(`0@)": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Queue EnqueueAndDequeue" + }, + "P:System.Collections.Generic.Queue`1.Count": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Queue EnqueueAndDequeue" + }, + "M:System.Collections.Generic.Queue`1.Contains(`0)": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "BulkOperations", + "title": "Queue BulkOperations", + "primary": true + }, + "M:System.Collections.Generic.Queue`1.Clear": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "BulkOperations", + "title": "Queue BulkOperations" + }, + "M:System.Collections.Generic.Queue`1.ToArray": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "BulkOperations", + "title": "Queue BulkOperations" + }, + "M:System.Collections.Generic.Queue`1.CopyTo(`0[],System.Int32)": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "BulkOperations", + "title": "Queue BulkOperations" + }, + "P:System.Collections.Generic.Queue`1.Capacity": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "Capacity", + "title": "Queue Capacity", + "primary": true + }, + "M:System.Collections.Generic.Queue`1.EnsureCapacity(System.Int32)": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "Capacity", + "title": "Queue Capacity" + }, + "M:System.Collections.Generic.Queue`1.TrimExcess": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "Capacity", + "title": "Queue Capacity" + }, + "M:System.Collections.Generic.Queue`1.TrimExcess(System.Int32)": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "Capacity", + "title": "Queue Capacity" + } +} diff --git a/src/libraries/System.Private.CoreLib/samples/samples.json b/src/libraries/System.Private.CoreLib/samples/samples.json new file mode 100644 index 00000000000000..b56679e2a899af --- /dev/null +++ b/src/libraries/System.Private.CoreLib/samples/samples.json @@ -0,0 +1,548 @@ +{ + "T:System.Collections.Generic.Dictionary`2": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Dictionary AddAndAccess", + "primary": true + }, + "M:System.Collections.Generic.Dictionary`2.Add(`0,`1)": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Dictionary AddAndAccess" + }, + "P:System.Collections.Generic.Dictionary`2.Item(`0)": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Dictionary AddAndAccess" + }, + "M:System.Collections.Generic.Dictionary`2.TryGetValue(`0,`1@)": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Dictionary AddAndAccess" + }, + "M:System.Collections.Generic.Dictionary`2.ContainsKey(`0)": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Dictionary AddAndAccess" + }, + "M:System.Collections.Generic.Dictionary`2.ContainsValue(`1)": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Dictionary AddAndAccess" + }, + "P:System.Collections.Generic.Dictionary`2.Count": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "AddAndAccess", + "title": "Dictionary AddAndAccess" + }, + "M:System.Collections.Generic.Dictionary`2.Remove(`0)": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "RemoveItems", + "title": "Dictionary RemoveItems", + "primary": true + }, + "M:System.Collections.Generic.Dictionary`2.Remove(`0,`1@)": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "RemoveItems", + "title": "Dictionary RemoveItems" + }, + "M:System.Collections.Generic.Dictionary`2.Clear": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "RemoveItems", + "title": "Dictionary RemoveItems" + }, + "P:System.Collections.Generic.Dictionary`2.Keys": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "BulkOperations", + "title": "Dictionary BulkOperations", + "primary": true + }, + "P:System.Collections.Generic.Dictionary`2.Values": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "BulkOperations", + "title": "Dictionary BulkOperations" + }, + "M:System.Collections.Generic.Dictionary`2.GetEnumerator": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "BulkOperations", + "title": "Dictionary BulkOperations" + }, + "P:System.Collections.Generic.Dictionary`2.Capacity": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "CapacityOperations", + "title": "Dictionary CapacityOperations", + "primary": true + }, + "M:System.Collections.Generic.Dictionary`2.EnsureCapacity(System.Int32)": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "CapacityOperations", + "title": "Dictionary CapacityOperations" + }, + "M:System.Collections.Generic.Dictionary`2.TrimExcess": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "CapacityOperations", + "title": "Dictionary CapacityOperations" + }, + "M:System.Collections.Generic.Dictionary`2.TrimExcess(System.Int32)": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "CapacityOperations", + "title": "Dictionary CapacityOperations" + }, + "M:System.Collections.Generic.Dictionary`2.TryAdd(`0,`1)": { + "file": "System/Collections/Generic/Dictionary.Examples.cs", + "method": "TryOperations", + "title": "Dictionary TryOperations" + }, + "M:System.Collections.Generic.HashSet`1.Add(`0)": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "AddAndContains", + "title": "Adding, querying, removing, and clearing elements", + "primary": true + }, + "M:System.Collections.Generic.HashSet`1.Contains(`0)": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "AddAndContains", + "title": "Adding, querying, removing, and clearing elements" + }, + "M:System.Collections.Generic.HashSet`1.Remove(`0)": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "AddAndContains", + "title": "Adding, querying, removing, and clearing elements" + }, + "M:System.Collections.Generic.HashSet`1.Clear": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "AddAndContains", + "title": "Adding, querying, removing, and clearing elements" + }, + "P:System.Collections.Generic.HashSet`1.Count": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "AddAndContains", + "title": "Adding, querying, removing, and clearing elements" + }, + "M:System.Collections.Generic.HashSet`1.UnionWith(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "SetOperations", + "title": "Union, intersection, difference, and symmetric difference", + "primary": true + }, + "M:System.Collections.Generic.HashSet`1.IntersectWith(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "SetOperations", + "title": "Union, intersection, difference, and symmetric difference" + }, + "M:System.Collections.Generic.HashSet`1.ExceptWith(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "SetOperations", + "title": "Union, intersection, difference, and symmetric difference" + }, + "M:System.Collections.Generic.HashSet`1.SymmetricExceptWith(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "SetOperations", + "title": "Union, intersection, difference, and symmetric difference" + }, + "M:System.Collections.Generic.HashSet`1.IsSubsetOf(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "SetComparisons", + "title": "Subset, superset, overlap, and equality comparisons", + "primary": true + }, + "M:System.Collections.Generic.HashSet`1.IsSupersetOf(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "SetComparisons", + "title": "Subset, superset, overlap, and equality comparisons" + }, + "M:System.Collections.Generic.HashSet`1.IsProperSubsetOf(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "SetComparisons", + "title": "Subset, superset, overlap, and equality comparisons" + }, + "M:System.Collections.Generic.HashSet`1.IsProperSupersetOf(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "SetComparisons", + "title": "Subset, superset, overlap, and equality comparisons" + }, + "M:System.Collections.Generic.HashSet`1.Overlaps(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "SetComparisons", + "title": "Subset, superset, overlap, and equality comparisons" + }, + "M:System.Collections.Generic.HashSet`1.SetEquals(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "SetComparisons", + "title": "Subset, superset, overlap, and equality comparisons" + }, + "M:System.Collections.Generic.HashSet`1.EnsureCapacity(System.Int32)": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "Capacity", + "title": "Managing HashSet capacity", + "primary": true + }, + "M:System.Collections.Generic.HashSet`1.TrimExcess": { + "file": "System/Collections/Generic/HashSet.Examples.cs", + "method": "Capacity", + "title": "Managing HashSet capacity" + }, + "T:System.Collections.Generic.List`1": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "AddAndInsert", + "title": "Create a List and add items", + "primary": true + }, + "M:System.Collections.Generic.List`1.#ctor": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "CapacityAndCount", + "title": "Create lists and manage capacity", + "primary": true + }, + "M:System.Collections.Generic.List`1.#ctor(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "AddAndInsert", + "title": "Create a List from a collection and add items" + }, + "M:System.Collections.Generic.List`1.#ctor(System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "CapacityAndCount", + "title": "Create a List with initial capacity" + }, + "M:System.Collections.Generic.List`1.Add(`0)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "AddAndInsert", + "title": "Add items to a List" + }, + "M:System.Collections.Generic.List`1.AddRange(System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "AddAndInsert", + "title": "Add a range of items to a List" + }, + "M:System.Collections.Generic.List`1.AsReadOnly": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "ConvertAndCopy", + "title": "Create a read-only wrapper", + "primary": true + }, + "M:System.Collections.Generic.List`1.BinarySearch(System.Int32,System.Int32,`0,System.Collections.Generic.IComparer{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Binary search within a range", + "primary": true + }, + "M:System.Collections.Generic.List`1.BinarySearch(`0)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Binary search a sorted List" + }, + "M:System.Collections.Generic.List`1.BinarySearch(`0,System.Collections.Generic.IComparer{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Binary search with a comparer" + }, + "P:System.Collections.Generic.List`1.Capacity": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "CapacityAndCount", + "title": "Manage List capacity" + }, + "M:System.Collections.Generic.List`1.Clear": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "RemoveItems", + "title": "Clear all items from a List" + }, + "M:System.Collections.Generic.List`1.Contains(`0)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Check if a List contains an item" + }, + "M:System.Collections.Generic.List`1.ConvertAll``1(System.Converter{`0,``0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "ConvertAndCopy", + "title": "Convert all items in a List" + }, + "M:System.Collections.Generic.List`1.CopyTo(System.Int32,`0[],System.Int32,System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "ConvertAndCopy", + "title": "Copy a range of items to an array" + }, + "M:System.Collections.Generic.List`1.CopyTo(`0[])": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "ConvertAndCopy", + "title": "Copy List to an array" + }, + "M:System.Collections.Generic.List`1.CopyTo(`0[],System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "ConvertAndCopy", + "title": "Copy List to an array at an index" + }, + "P:System.Collections.Generic.List`1.Count": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "CapacityAndCount", + "title": "Get the number of items in a List" + }, + "M:System.Collections.Generic.List`1.EnsureCapacity(System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "CapacityAndCount", + "title": "Ensure minimum capacity" + }, + "M:System.Collections.Generic.List`1.Exists(System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Check if any item matches a predicate" + }, + "M:System.Collections.Generic.List`1.Find(System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "FindItems", + "title": "Find the first matching item", + "primary": true + }, + "M:System.Collections.Generic.List`1.FindAll(System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "FindItems", + "title": "Find all matching items" + }, + "M:System.Collections.Generic.List`1.FindIndex(System.Int32,System.Int32,System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "FindItems", + "title": "Find index within a range" + }, + "M:System.Collections.Generic.List`1.FindIndex(System.Int32,System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "FindItems", + "title": "Find index starting at an offset" + }, + "M:System.Collections.Generic.List`1.FindIndex(System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "FindItems", + "title": "Find the index of the first match" + }, + "M:System.Collections.Generic.List`1.FindLast(System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "FindItems", + "title": "Find the last matching item" + }, + "M:System.Collections.Generic.List`1.FindLastIndex(System.Int32,System.Int32,System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "FindItems", + "title": "Find last index within a range" + }, + "M:System.Collections.Generic.List`1.FindLastIndex(System.Int32,System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "FindItems", + "title": "Find last index up to an offset" + }, + "M:System.Collections.Generic.List`1.FindLastIndex(System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "FindItems", + "title": "Find the index of the last match" + }, + "M:System.Collections.Generic.List`1.ForEach(System.Action{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "Iterate", + "title": "Execute an action on each item", + "primary": true + }, + "M:System.Collections.Generic.List`1.GetEnumerator": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "Iterate", + "title": "Get an enumerator for the List" + }, + "M:System.Collections.Generic.List`1.GetRange(System.Int32,System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "ConvertAndCopy", + "title": "Get a range of items as a new List" + }, + "M:System.Collections.Generic.List`1.IndexOf(`0)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Find the index of an item" + }, + "M:System.Collections.Generic.List`1.IndexOf(`0,System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Find the index starting at an offset" + }, + "M:System.Collections.Generic.List`1.IndexOf(`0,System.Int32,System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Find the index within a range" + }, + "M:System.Collections.Generic.List`1.Insert(System.Int32,`0)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "AddAndInsert", + "title": "Insert an item at an index" + }, + "M:System.Collections.Generic.List`1.InsertRange(System.Int32,System.Collections.Generic.IEnumerable{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "AddAndInsert", + "title": "Insert a range of items at an index" + }, + "P:System.Collections.Generic.List`1.Item(System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "Indexer", + "title": "Access items by index" + }, + "M:System.Collections.Generic.List`1.LastIndexOf(`0)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Find the last index of an item" + }, + "M:System.Collections.Generic.List`1.LastIndexOf(`0,System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Find the last index up to an offset" + }, + "M:System.Collections.Generic.List`1.LastIndexOf(`0,System.Int32,System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Find the last index within a range" + }, + "M:System.Collections.Generic.List`1.Remove(`0)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "RemoveItems", + "title": "Remove the first occurrence of an item" + }, + "M:System.Collections.Generic.List`1.RemoveAll(System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "RemoveItems", + "title": "Remove all items matching a predicate" + }, + "M:System.Collections.Generic.List`1.RemoveAt(System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "RemoveItems", + "title": "Remove an item at an index" + }, + "M:System.Collections.Generic.List`1.RemoveRange(System.Int32,System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "RemoveItems", + "title": "Remove a range of items" + }, + "M:System.Collections.Generic.List`1.Reverse": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SortAndReverse", + "title": "Reverse the order of items", + "primary": true + }, + "M:System.Collections.Generic.List`1.Reverse(System.Int32,System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SortAndReverse", + "title": "Reverse a range of items" + }, + "M:System.Collections.Generic.List`1.Slice(System.Int32,System.Int32)": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "ConvertAndCopy", + "title": "Get a slice of items as a new List" + }, + "M:System.Collections.Generic.List`1.Sort": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SortAndReverse", + "title": "Sort items in default order" + }, + "M:System.Collections.Generic.List`1.Sort(System.Collections.Generic.IComparer{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SortAndReverse", + "title": "Sort items with a comparer" + }, + "M:System.Collections.Generic.List`1.Sort(System.Comparison{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SortAndReverse", + "title": "Sort items with a comparison delegate" + }, + "M:System.Collections.Generic.List`1.Sort(System.Int32,System.Int32,System.Collections.Generic.IComparer{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SortAndReverse", + "title": "Sort a range of items" + }, + "M:System.Collections.Generic.List`1.ToArray": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "ConvertAndCopy", + "title": "Convert a List to an array" + }, + "M:System.Collections.Generic.List`1.TrimExcess": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "CapacityAndCount", + "title": "Trim excess capacity" + }, + "M:System.Collections.Generic.List`1.TrueForAll(System.Predicate{`0})": { + "file": "System/Collections/Generic/List.Examples.cs", + "method": "SearchItems", + "title": "Check if all items match a predicate" + }, + "T:System.Collections.Generic.Queue`1": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Queue EnqueueAndDequeue", + "primary": true + }, + "M:System.Collections.Generic.Queue`1.#ctor": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Queue EnqueueAndDequeue" + }, + "M:System.Collections.Generic.Queue`1.Enqueue(`0)": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Queue EnqueueAndDequeue" + }, + "M:System.Collections.Generic.Queue`1.Dequeue": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Queue EnqueueAndDequeue" + }, + "M:System.Collections.Generic.Queue`1.Peek": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Queue EnqueueAndDequeue" + }, + "M:System.Collections.Generic.Queue`1.TryDequeue(`0@)": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Queue EnqueueAndDequeue" + }, + "M:System.Collections.Generic.Queue`1.TryPeek(`0@)": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Queue EnqueueAndDequeue" + }, + "P:System.Collections.Generic.Queue`1.Count": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "EnqueueAndDequeue", + "title": "Queue EnqueueAndDequeue" + }, + "M:System.Collections.Generic.Queue`1.Contains(`0)": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "BulkOperations", + "title": "Queue BulkOperations" + }, + "M:System.Collections.Generic.Queue`1.Clear": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "BulkOperations", + "title": "Queue BulkOperations" + }, + "M:System.Collections.Generic.Queue`1.ToArray": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "BulkOperations", + "title": "Queue BulkOperations" + }, + "M:System.Collections.Generic.Queue`1.CopyTo(`0[],System.Int32)": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "BulkOperations", + "title": "Queue BulkOperations" + }, + "P:System.Collections.Generic.Queue`1.Capacity": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "Capacity", + "title": "Queue Capacity" + }, + "M:System.Collections.Generic.Queue`1.EnsureCapacity(System.Int32)": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "Capacity", + "title": "Queue Capacity" + }, + "M:System.Collections.Generic.Queue`1.TrimExcess": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "Capacity", + "title": "Queue Capacity" + }, + "M:System.Collections.Generic.Queue`1.TrimExcess(System.Int32)": { + "file": "System/Collections/Generic/Queue.Examples.cs", + "method": "Capacity", + "title": "Queue Capacity" + } +}