Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
A statement uses the AddressOf
operator with an operand that represents a procedure of the Nullable<T> structure.
Error ID: BC32126
Replace the procedure name in the
AddressOf
clause with an operand that is not a member of Nullable<T>.Write a class that wraps the method of Nullable<T> that you want to use. In the following example, the
NullableWrapper
class defines a new method namedGetValueOrDefault
. Because this new method is not a member of Nullable<T>, it can be applied tonullInstance
, an instance of a nullable type, to form an argument forAddressOf
.
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
.NET feedback
.NET is an open source project. Select a link to provide feedback: