Skip to content

Readonly Modifier in C#: retarget net10.0, Playlist, Counter/Tally trap, Book init property - #2303

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/94906-csharp-readonly-modifier
Open

vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/94906-csharp-readonly-modifier

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Sample update for the article "Readonly Modifier in C#" (https://code-maze.com/csharp-readonly-modifier/). Touches only csharp-intermediate-topics/ReadOnlyModifierInCSharp.

  • 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.
  • New Playlist: a readonly List<string> field that still accepts items; the reassignment in Reset() stays commented out as a compiler error, matching the sample's convention.
  • New Counter (mutable struct with a readonly Describe() method) and Tally (a readonly Counter field: Increment() runs on a defensive copy, so Total stays 0).
  • New Book with a required init-only Title.
  • Program.cs prints each one. Three new tests pin the readonly list change, the Total of 0 and a Counter variable reaching 2. Existing files and tests unchanged.

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

…ap, Book init property, three tests

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. New Playlist (a readonly List<string> field that still accepts items; the reassignment in Reset() stays commented out as a compiler error), Counter (a mutable struct with a readonly Describe() method), Tally (a readonly Counter field whose Increment() calls run on a defensive copy, so Total stays 0) and Book (required init-only Title). Program.cs prints each one. Three new tests: the readonly list changes, the readonly struct field total stays 0, and a Counter variable increments to 2. Existing files and tests unchanged.
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