Skip to content

ToDictionary in C#: .NET 10 sample with every overload shape, duplicate keys and ToLookup - #2290

Merged
vladimir-pecanac-main merged 2 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/116977-csharp-linq-todictionary-method
Oct 12, 2026
Merged

vladimir-pecanac-main merged 2 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/116977-csharp-linq-todictionary-method

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Sample update for the article "ToDictionary in C#: Collection to Dictionary" (https://code-maze.com/csharp-linq-todictionary-method/).

Changes, all inside csharp-linq/ToDictionaryMethodInCSharp:

  • Both projects retargeted from net8.0 to net10.0.
  • Test packages, re-queried on NuGet on 2026-10-11 (latest listed stable): Microsoft.NET.Test.Sdk 18.10.1, xunit 2.9.3, xunit.runner.visualstudio 4.0.1, coverlet.collector 10.1.0. The test framework stays xunit.
  • Kenya added to the sample list, so Egypt and Kenya share the continent Africa. Both expectation lists in the tests gain Kenya.
  • Six new methods, one per new snippet in the article: CallToDictionaryOnKeyValuePairs, CallToDictionaryOnTuples, CallToDictionaryWithComparer, CallToDictionaryWithDuplicateKeys (throws), CallToDictionaryKeepingFirstPerContinent and CallToLookupOnContinents.
  • One test per new method. The duplicate-key test asserts the ArgumentException message "An item with the same key has already been added. Key: Africa".

Local run on SDK 10.0.302, runtime 10.0.10: dotnet build -c Release 0 warnings, 0 errors; dotnet test 8 passed, 0 failed; dotnet list package --vulnerable --include-transitive reports no vulnerable packages.

… ToLookup

Retarget both projects to net10.0 and bump the test packages
(Microsoft.NET.Test.Sdk 18.10.1, xunit 2.9.3, xunit.runner.visualstudio 4.0.1,
coverlet.collector 10.1.0).

Add Kenya to the sample list so two countries share the continent Africa,
and update both expectation lists. Add the KeyValuePair and tuple overloads,
a case-insensitive comparer, the duplicate-key exception, DistinctBy before
ToDictionary, and ToLookup, each with a test.
@vladimir-pecanac-main
vladimir-pecanac-main merged commit 9f20ab1 into CodeMazeBlog:main Oct 12, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant