C
C#3y 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
ero3y 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
Thinker3y 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
LukeJOP3y ago
Ah. I completely autopiloted making it of that type. Learning functional programming and it's a lot to take in catsweat
Thinker
Thinker3y ago
FP be like... type parameters, type parameters everywhere
LukeJ
LukeJOP3y ago
!solved .solved .close
Thinker
Thinker3y ago
/close
LukeJ
LukeJOP3y ago
God damn it I forgot how it's done here. Thanks
Accord
Accord3y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server