は、ここで私はCSHARPでやってみたいものだが、私は(私はこれがC#
有効ではありません知っているを)これを行う方法を知らない:enumをキーとして文字列のconst配列を作る方法は?
const enum GameOver { Winner, Looser, Tied, };
GameOvers = [
GameOver.Winner: "Person is the winner",
GameOver.Looser: "Person is the looser",
GameOver.Tied: "Game is tied",
]
を、後に、私が呼び出すことができるようにしたいですそれは好きです:
Display(GameOvers[GameOver.Winner])
(私はこのようなエラーのconst配列を実際に処理したいです)。
C#
でどうやったらいいですか?インスタンスが変更可能であるので、あなたは、Dictionary
が実際に一定にすることができないこと、
enum GameOver { Winner, Loser, Tied };
Dictionary<GameOver, string> GameOvers = new Dictionary<GameOver, string>()
{
{GameOver.Winner, "Person is the winner"},
{GameOver.Loser, "Person is the loser"},
{GameOver.Tied, "Game is tied"}
};
しかし予告:
[説明]属性または[これと類似のもの](https://stackoverflow.com/q/424366/1070452)を使用できますか? – Plutonix
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/how-to-initialize-a-dictionary-with-a-collection-initializer –
この質問は、あなたが必要とするものを持っています:https://stackoverflow.com/questions/479410/enum-tostring-with-user-friendly-strings –