C
C#2y ago
MuffinMan

✅ Is it possible to put a generic constraint on a record?

If I have a record Card<T> (....) and I want to put a constraint on it, such as where T : class? is there any way of doing this? The syntax does seem to be liked in my IDE (rider). All of the information I am trying to look up talks about the problem of making a constraint on T being a record, which is not even a thing.
6 Replies
MODiX
MODiX2y ago
Orannis#3333
REPL Result: Success
record Card<T>(string Suit, int Number) where T : class {}
record Card<T>(string Suit, int Number) where T : class {}
Compile: 477.853ms | Execution: 86.262ms | React with ❌ to remove this embed.
MuffinMan
MuffinManOP2y ago
I was trying to use this with positional parameter syntax I suppose that is not supported.
333fred
333fred2y ago
That's what I showed 🙂
MuffinMan
MuffinManOP2y ago
oops oh that is why I missed it thanks!
333fred
333fred2y ago
You're welcome. Please $close if there's nothing else
MODiX
MODiX2y ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server