C
C#2y ago
LukeJ

Can't access record members [Answered]

I have a record that looks like this
public readonly record struct Card(Suite suite, Rank rank);
public readonly record struct Card(Suite suite, Rank rank);
And am making a record that looks like this
public readonly record struct StandardCard<Card> {
public readonly Card card;

public StandardCard(Card card) {
this.card = card;
}
}
public readonly record struct StandardCard<Card> {
public readonly Card card;

public StandardCard(Card card) {
this.card = card;
}
}
I'm new to messing with records, so can't figure something out. Why can't I do card.suite or card.rank in that constructor? I can do it elsewhere in my doe, but not here.
8 Replies
ero
ero2y ago
why do you need the record to look like that specifically? why can't you do public readonly record struct StandardCard<Card>(Card card);? nevermind the fact that you use absolutely incorrect naming, and the fact that a generic param on StandardCard is probably just wrong
Thinker
Thinker2y ago
I think you might be confusing generics here with what you actually want. Is Card meant to be a type parameter of StandardCard or its own type? Because StandardCard<Card> will make Card into a type parameter
LukeJ
LukeJ2y ago
Ah. I completely autopiloted making it of that type. Learning functional programming and it's a lot to take in catsweat
Thinker
Thinker2y ago
FP be like... type parameters, type parameters everywhere
LukeJ
LukeJ2y ago
!solved .solved .close
Thinker
Thinker2y ago
/close
LukeJ
LukeJ2y ago
God damn it I forgot how it's done here. Thanks
Accord
Accord2y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server
More Posts