Métodos de 'System.Nullable (Of T)' não podem ser usados como operandos do operador 'AddressOf'
Uma instrução usa o operador AddressOf com um operando que representa um procedimento da estrutura Nullable<T>.
ID de erro: BC32126
Para corrigir este erro
Substitua o nome do procedimento na cláusula AddressOf com um operando que não seja um membro de Nullable<T>.
Escreva uma classe que quebra o método de Nullable<T> que você deseja usar.No exemplo a seguir, a classe NullableWrapper define um novo método chamado GetValueOrDefault.Como esse novo método não é um membro do Nullable<T>, ele pode ser aplicado a nullInstance, uma instância de uma tipo anulável, para formar um argumento para AddressOf.
Module Module1 Delegate Function Deleg() As Integer Sub Main() Dim nullInstance As New Nullable(Of Integer)(1) Dim del As Deleg ' GetValueOrDefault is a method of the Nullable generic ' type. It cannot be used as an operand of AddressOf. ' del = AddressOf nullInstance.GetValueOrDefault ' The following line uses the GetValueOrDefault method ' defined in the NullableWrapper class. del = AddressOf (New NullableWrapper(Of _ Integer)(nullInstance)).GetValueOrDefault Console.WriteLine(del.Invoke()) End Sub Class NullableWrapper(Of T As Structure) Private m_Value As Nullable(Of T) Sub New(ByVal Value As Nullable(Of T)) m_Value = Value End Sub Public Function GetValueOrDefault() As T Return m_Value.Value End Function End Class End Module
Consulte também
Conceitos
Tipos genéricos no Visual Basic