Export (0) Print
Expand All

Nullable(Of T).ToString Method

Returns the text representation of the value of the current Nullable(Of T) object.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

'Declaration
Public Overrides Function ToString As String

Return Value

Type: System.String
The text representation of the value of the current Nullable(Of T) object if the HasValue property is true, or an empty string ("") if the HasValue property is false.

The ToString property returns the string yielded by calling the ToString property of the object returned by the Value property.

The following code example displays the value of the current Nullable(Of T) object.


' This code example demonstrates the 
' Nullable<T>.ToString method.


Class Example
   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Dim nullableDate As Nullable(Of DateTime)
      ' Display the current date and time.
      nullableDate = DateTime.Now
      Display(outputBlock, "1)", nullableDate)

      ' Assign null (Nothing in Visual Basic) to nullableDate, then 
      ' display its value.
      nullableDate = Nothing
      Display(outputBlock, "2)", nullableDate)
   End Sub 'Main

   '  Display the text representation of a nullable DateTime.
   Public Shared Sub Display(ByVal outputBlock As System.Windows.Controls.TextBlock, ByVal title As String, _
                             ByVal dspDT As Nullable(Of DateTime))
      Dim msg As String = dspDT.ToString()

      outputBlock.Text += String.Format("{0} ", title)
      If String.IsNullOrEmpty(msg) Then
         outputBlock.Text &= "The nullable DateTime has no defined value." & vbCrLf
      Else
         outputBlock.Text += String.Format("The current date and time is {0}.", msg) & vbCrLf
      End If
   End Sub 'Display 
End Class 'Sample

'This code example produces the following results:
'
'1) The current date and time is 4/19/2005 8:28:14 PM.
'2) The nullable DateTime has no defined value.
'


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2014 Microsoft