1

この vb.net 行を厳密な証明に変換する際に問題が発生しています

[Enum].GetValues(GetType(ReferenceOutput))(DataGrid1.SelectedIndex)

ReferenceOutput はクラスであり、datagrid1.selectedindex は datagrid で選択されたものです。これを厳密な証明行に変換するにはどうすればよいですか。次のエラーが表示されます。

Error   1   Option Strict On disallows late binding.

ありがとう

4

1 に答える 1

4

最も堅牢なアプローチEnum.TryParseは、新しいジェネリック メソッドを使用することです。

Dim refOutput As ReferenceOutput
Dim enumValue = DataGrid1.SelectedIndex.ToString()
If [Enum].TryParse(enumValue, refOutput) Then
    Console.WriteLine("Converted '{0}' to {1}.", enumValue, refOutput.ToString())
Else
    Console.WriteLine("{0} is not a member of the ReferenceOutput enumeration.", enumValue)
End If

これは、古い冗長でチェックされていないボックス化解除のアプローチです。

Dim refOutput As ReferenceOutput = DirectCast([Enum].Parse(GetType(ReferenceOutput), DataGrid1.SelectedIndex.ToString(), True), ReferenceOutput)
于 2012-10-25T12:05:09.137 に答える