G
george r smith
I am converting a delphi chess program to C#, this is how I study a new
language and I have the following problem.
How do you use an enumeration value as an indexer for an array ?
This is what I have come up with, but it seems vebose. In Delphi I would
just say
PieceValue[Queen] instead of PieceValue[(int)Piece.Queen].
This is ok if it is the only way but is there a better C# way.
thanks
grs
class Class1
{
enum Piece
{
Queen,
Pawn
};
static void Main()
{
int[] PieceValue = {8,1};
Console.WriteLine(PieceValue[(int)Piece.Queen]);
Console.WriteLine(PieceValue[(int)Piece.Pawn]);
}
}
language and I have the following problem.
How do you use an enumeration value as an indexer for an array ?
This is what I have come up with, but it seems vebose. In Delphi I would
just say
PieceValue[Queen] instead of PieceValue[(int)Piece.Queen].
This is ok if it is the only way but is there a better C# way.
thanks
grs
class Class1
{
enum Piece
{
Queen,
Pawn
};
static void Main()
{
int[] PieceValue = {8,1};
Console.WriteLine(PieceValue[(int)Piece.Queen]);
Console.WriteLine(PieceValue[(int)Piece.Pawn]);
}
}