Fixed size array

.net, arrays, c#

Solution

The size of an array is not part of its type.

You need to create it with that size:

public Card[] Hand {get; set;}

public MyClass()
{
    Hand = new Card[4];
}

You could also use a full property and initialize the array to that size.

private Card[] hand = new Card[4];
public Card[] Hand
{
    get { return hand; }
    //Set if you want!
}

Problem

I'm developing a WPF game with C# and .NET Framework 4.5.1. I have this class: ``` public class Player { public Card[4] Hand { get; set; } } ``` And I need to set that `Player.Hand` can only contain four cards (`Card` is a class that represent a card). How can I do it? The above code show the exception `"matrix size cannot be specified in variable declaration"`. And if I use `List<Card>()`, I can set max size.

Original source