回答編集履歴
3
文章の修正
answer
CHANGED
File without changes
|
2
文章の修正
answer
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
[Enum.Parse](https://docs.microsoft.com/ja-jp/dotnet/api/system.enum.parse?view=netcore-3.1)を使
|
1
|
+
[Enum.Parse](https://docs.microsoft.com/ja-jp/dotnet/api/system.enum.parse?view=netcore-3.1)を使い、第2引数にドロップダウンのテキストを渡すことで対応する`CardType`の値が取得できます。
|
2
|
-
ただし、正しい形式の文字列を渡さないと`ArgumentException`が発生しますので注意してください。
|
3
2
|
|
4
3
|
```C#
|
5
4
|
// CardType.光
|
@@ -8,4 +7,8 @@
|
|
8
7
|
Console.WriteLine((CardType)Enum.Parse(typeof(CardType),"ドラゴン"));
|
9
8
|
// CardType.岩石 | CardType.炎
|
10
9
|
Console.WriteLine((CardType)Enum.Parse(typeof(CardType),"岩石, 炎"));
|
11
|
-
```
|
10
|
+
```
|
11
|
+
|
12
|
+
この方法では、列挙型に定義されている名前付き定数と同様の文字列を渡さないと`ArgumentException`が発生しますので注意してください。
|
13
|
+
|
14
|
+
つまり、ドロップダウンに表示するテキストは`CardType`内の名前付き定数と合わせる必要があります。
|
1
コード修正
answer
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
ただし、正しい形式の文字列を渡さないと`ArgumentException`が発生しますので注意してください。
|
3
3
|
|
4
4
|
```C#
|
5
|
-
//
|
5
|
+
// CardType.光
|
6
6
|
Console.WriteLine((CardType)Enum.Parse(typeof(CardType),"光"));
|
7
|
-
//
|
7
|
+
// CardType.ドラゴン
|
8
8
|
Console.WriteLine((CardType)Enum.Parse(typeof(CardType),"ドラゴン"));
|
9
|
-
//
|
9
|
+
// CardType.岩石 | CardType.炎
|
10
10
|
Console.WriteLine((CardType)Enum.Parse(typeof(CardType),"岩石, 炎"));
|
11
11
|
```
|