C#C
C#10mo ago
Trapyy

✅ When to use each constructor?

public class InventorySlot(Item item, int quantity)
{
    public Item Item { get; } = item;
    public int Quantity { get; private set; } = quantity;
}

or
public class InventorySlot
{
    public Item Item { get; } 
    public int Quantity { get; private set; }

    public InventorySlot(Item item, int quantity)
    {
        Item = item;
        Quantity = quantity;
    }
}
Was this page helpful?