Skip to content

IEnumerable in C#: retarget net10.0, Book record, GenericLibrary with yield return - #2297

Merged
vladimir-pecanac-main merged 2 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/78387-csharp-ienumerable
Oct 23, 2026
Merged

vladimir-pecanac-main merged 2 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/78387-csharp-ienumerable

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Sample update for the article "IEnumerable in C#" (https://code-maze.com/csharp-ienumerable/). Touches only collections-csharp/IEnumerableCSharp.

  • Both projects retargeted from net7.0 to net10.0.
  • Test packages: Microsoft.NET.Test.Sdk 18.11.0, xunit 2.9.3, xunit.runner.visualstudio 4.0.1, coverlet.collector 10.1.0.
  • Book is now a positional record; the Library constructor copies the array with a collection expression; Program.cs uses top-level statements; file-scoped namespaces throughout.
  • New GenericLibrary implements IEnumerable<Book> with yield return, and Program.cs runs a LINQ query on it.
  • The test project now references the console project. New LibraryTests: iteration returns every book in order, Cast<Book>() before LINQ on the non-generic Library, LINQ directly on GenericLibrary, and Reset() on the compiler-generated enumerator throws NotSupportedException. The five existing tests are unchanged.

Local run on SDK 10.0.302 / .NET 10.0.10: build 0 warnings, 0 errors; tests 9 passed, 0 failed; dotnet list package --vulnerable --include-transitive reports none.

… yield return, LibraryTests

Both projects net7.0 to net10.0. Microsoft.NET.Test.Sdk 18.11.0, xunit 2.9.3, xunit.runner.visualstudio 4.0.1, coverlet.collector 10.1.0. Book becomes a positional record, the Library constructor copies with a collection expression, Program.cs moves to top-level statements and gains the GenericLibrary query, file-scoped namespaces. New GenericLibrary implements IEnumerable<Book> with yield return. The test project references the console project and gains LibraryTests (iteration order from the -1 start, Cast before LINQ on the non-generic Library, LINQ directly on GenericLibrary, Reset on the generated enumerator throws NotSupportedException).
@vladimir-pecanac-main
vladimir-pecanac-main merged commit 174bb2e into CodeMazeBlog:main Oct 23, 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