Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
Aggiornamento: novembre 2007
Methods of 'System.Nullable(Of T)' cannot be used as operands of the 'AddressOf' operator
Un'istruzione utilizza l'operatore AddressOf con un operando che rappresenta una routine della struttura Nullable<T>.
ID errore: BC32126
Per correggere l'errore
Sostituire il nome della routine nella clausola AddressOf con un operando che non sia membro di Nullable<T>.
Scrivere una classe che effettui il wrapping del metodo di Nullable<T> da utilizzare. Nell'esempio riportato di seguito, la classe NullableWrapper definisce un nuovo metodo denominato GetValueOrDefault. Poiché questo nuovo metodo non è un membro di Nullable<T>, può essere applicato a nullInstance, un'istanza di tipo nullable, per formare un argomento per 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