© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
11 replies
LukeJ

Cannot set readonly field in inherited constructor [Answered]

Title says it all really, I'm not really sure why given this is clearly a constructor.
public class StandardCard : Card {
    public StandardCard(Suite suite, Rank rank) {
        if (!StandardRanks.ranks.Contains(rank))
            throw new Exception();

        this.suite = suite;
        this.rank = rank;
    }
}
public class StandardCard : Card {
    public StandardCard(Suite suite, Rank rank) {
        if (!StandardRanks.ranks.Contains(rank))
            throw new Exception();

        this.suite = suite;
        this.rank = rank;
    }
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Make set accessor of inherited prop private
C#CC# / help
4y ago
Cannot create comparer [Answered]
C#CC# / help
4y ago