0

The class Player herits from Deckholder where the property Deck has been declared.

public class Deckholder
{
    public Deck Deck { get; set; }

    public Deckholder(Deck deck)
    {
        Deck = deck;
    }
}
public class Player : Deckholder

{
    public string Name { get; set; }
    public int Score { get; set; }

    public Player(string name, Deck deck)
    {
        Deck = deck;
        Name = name;
        Score = 0;
    }

VSCode tells me, that

No argument that fits the formal parameter "deck" from "Deckholder.Deckholder(Deck) was found."

with red squiggles under the Player-constructor. But how do I fix this? I mean I do have a Deck deck as a parameter and I need that.

xzeed
  • 45
  • 1
  • 5
  • 1
    You have to call the base constructor: `public Player(string name, Deck deck) : base(deck)`. – Johnathan Barclay Feb 02 '22 at 12:48
  • 1
    BTW: this is not an [attribute](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/attributes/) but a [property](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/properties) – Klaus Gütter Feb 02 '22 at 12:53
  • @KlausGütter Ah yes, thank you. – xzeed Feb 02 '22 at 12:56

1 Answers1

3

You have to call the constructor of the Deckholderclass from your constructor of your Player class. Use the base keyword for this:

public Player(string name, Deck deck) : base(deck)
{
    Name = name;
    Score = 0;
}

You don't have to assign deck in the Player class anymore, because it is done in the base constructor.

SomeBody
  • 7,515
  • 2
  • 17
  • 33