Skip to content

Concatenate Lists in C#: net10.0, collection expression, parameterised benchmark - #2278

Merged
vladimir-pecanac-main merged 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/72942-csharp-concatenate-lists
Oct 11, 2026
Merged

vladimir-pecanac-main merged 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/72942-csharp-concatenate-lists

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Sample update for the article "Concatenate Lists in C#: How to Combine Two Lists" (https://code-maze.com/csharp-concatenate-lists/).

Changes, all inside collections-lists/ConcatenateLists:

  • All three projects move from net6.0 to net10.0.
  • New UsingCollectionExpression method ([.. firstList, .. secondList]) with a test and a benchmark.
  • New UsingAddNoCapacity and UsingAddRangeNoCapacity methods with tests and benchmarks, so the article's list-capacity comparison is measured by committed code.
  • ConcatenatorBenchmark: [Params(50_000, 1_000_000)] on a Size field, and inputs built in [GlobalSetup] as distinct strings (Code0..CodeN and Maze0..MazeN). The old Enumerable.Repeat inputs made Union return two elements while every other method returned two million.
  • Count() replaced by the Count property (seven call sites in Concatenator.cs, six in Tests.cs).
  • UsingCopyTo: the string[] variable is named combinedArray and both CopyTo calls use the two-argument overload.
  • ConcatenateLists/Program.cs converted to top-level statements; Console.ReadLine removed.
  • New test: Union returns one element for ["a", "a"] and ["a"].

Package versions, re-queried on NuGet on 2026-10-10 (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
  • BenchmarkDotNet 0.15.8

Local results on SDK 10.0.302 / runtime 10.0.10: dotnet build -c Release 0 warnings 0 errors; dotnet test 10 passed, 0 failed; dotnet list package --vulnerable --include-transitive reports no vulnerable packages in any project.

…hmark with distinct data

- Retarget all three projects to net10.0; Test.Sdk 18.10.1, xunit 2.9.3, xunit.runner.visualstudio 4.0.1, coverlet.collector 10.1.0, BenchmarkDotNet 0.15.8
- Add UsingCollectionExpression with a test and a benchmark
- Add UsingAddNoCapacity and UsingAddRangeNoCapacity with tests and benchmarks
- Benchmark: [Params(50_000, 1_000_000)] Size and distinct input strings built in [GlobalSetup]
- Count() to Count on List<string> (seven in Concatenator.cs, six in Tests.cs)
- UsingCopyTo: combinedList renamed combinedArray, two-argument CopyTo for both calls
- ConcatenateLists/Program.cs to top-level statements, Console.ReadLine dropped
- Test that Union returns one element for duplicates inside and across the lists
@vladimir-pecanac-main
vladimir-pecanac-main merged commit d1d342f into CodeMazeBlog:main Oct 11, 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