Repository navigation
Add type selection guidance matrix and static class design guidance (Fixes #42512) - #56655
Open
Manish-1kumar wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The struct and record struct descriptions make inaccurate allocation guarantees and should describe value semantics without promising stack-only or allocation-free behavior.
1 open issue
What changed in this PR
Expands the C# classes article with type-selection and static-class design guidance to address #42512.
Changes:
- Adds a comparison matrix for seven type constructs, covering categories, equality, and use cases.
- Explains when to use static classes and when to prefer instantiable services and interfaces.
- Updates the article’s date.
| File | Description |
|---|---|
docs/csharp/fundamentals/types/classes.md |
Adds type-selection guidance and recommendations for static-class design. |
Review effort: Balanced
Comment on lines
+34
to
+36
| | `struct` | Value type | Value equality | Small, short-lived data structures (≤ 16 bytes), math primitives, coordinates, and performance-critical algorithms requiring stack allocation. | | ||
| | `record class` | Reference type | Value equality | Data Transfer Objects (DTOs), API models, immutable domain models, and messages with built-in value-based equality and `with` expressions. | | ||
| | `record struct` | Value type | Value equality | Small data models requiring value-based semantics and `with` expressions without heap allocations. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
Resolves #42512.
In \docs/csharp/fundamentals/types/classes.md, adds structured architectural guidance for choosing between C# type constructs (\class, \static class, \struct,
ecord class,
ecord struct, tuple, and \interface), and documents design guidance for when to create static classes.
Changes Included
Internal previews
Build report