DEV Community

Discussion on: What's the point of a `readonly struct` if the types aren't implicitly made `readonly`?

Collapse
 
mileswatson profile image
Miles Watson • Edited

It makes it clearer to other programmers that they shouldn’t try and add mutable fields. It also has the added benefit of allowing better compiler optimisation. I would recommend using a record as opposed to a read only struct in most situations.

docs.microsoft.com/en-us/dotnet/st...