How to Choose Among Class, Record, and Struct in C#
spin.atomicobject.com·6d
🔢Algebraic Data Types
Preview
Report Post

If you write C#, you eventually need to decide whether a type should be a class, a struct, or a record. All three can represent data, but they communicate different intent and come with different tradeoffs around equality, mutability, and usage.

I’ll walk you through how these types are commonly used in C#, how they differ, and some practical guidance for choosing among them.

A Useful Distinction: Identity vs. Value

One way to compare these types is by looking at whether a type represents identity or value.

A type with…

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help