Generic type constraint for records (or more general an immutable type) #3899
-
Consider this example of a delegate:
In my example I want to make sure that implementers are not able to alter the state, so I want to enforce T to be an immutable type.
Adding the constraint would be a solution. Would be great if an option like this would be available in the language. Thanks for your time |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Duplicate of #3859 / #39 (comment). In short, there is intentionally no way to distinguish between a record and a regular class, and there is no desire to change that. |
Beta Was this translation helpful? Give feedback.
-
There's also the issue of records not being immutable, despite how much the documentation claims that they are. |
Beta Was this translation helpful? Give feedback.
-
C# has no such concept. Note: records are not immutable. Evenif we could add a |
Beta Was this translation helpful? Give feedback.
-
I have this situation:
This is totaly fine. But when variable |
Beta Was this translation helpful? Give feedback.
Duplicate of #3859 / #39 (comment).
In short, there is intentionally no way to distinguish between a record and a regular class, and there is no desire to change that.