Skip to content

Add type selection guidance matrix and static class design guidance (Fixes #42512) - #56655

Open
Manish-1kumar wants to merge 1 commit into
dotnet:mainfrom
Manish-1kumar:users/manish/issue-42512-guidance-choosing-types-and-static-classes
Open

Manish-1kumar wants to merge 1 commit into
dotnet:mainfrom
Manish-1kumar:users/manish/issue-42512-guidance-choosing-types-and-static-classes

Conversation

@Manish-1kumar

@Manish-1kumar Manish-1kumar commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Added a Choose between type constructs comparison matrix detailing type categories (reference vs value vs contract), equality behaviors, and primary use cases.
  • Added a When to create a static class subsection detailing when static classes are appropriate (stateless utilities, extension methods, pure factories) and when an instantiable service with an interface is preferable (polymorphism, test mocking, and dependency injection).\
  • Validated with \markdownlint-cli2\ (0 issues).

Internal previews

File Preview link
_csharplang/proposals/csharp-14.0/async-main-update.md Learn preview
docs/csharp/fundamentals/types/classes.md Learn preview

Build report

@dotnetrepoman dotnetrepoman Bot added this to the November 2026 milestone Nov 1, 2026
@dotnet-policy-service dotnet-policy-service Bot added dotnet-csharp/svc fundamentals/subsvc community-contribution Indicates PR is created by someone from the .NET community. labels Nov 1, 2026
@BillWagner
BillWagner requested a balanced review from Copilot November 24, 2026 14:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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. |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates PR is created by someone from the .NET community. dotnet-csharp/svc fundamentals/subsvc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

This article (or this section) should discuss static classes and when to create them

2 participants