diff --git a/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_1.vb b/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_1.vb deleted file mode 100644 index 6a4be4160b4f8..0000000000000 --- a/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_1.vb +++ /dev/null @@ -1,3 +0,0 @@ - Dim ridesBusToWork1? As Boolean - Dim ridesBusToWork2 As Boolean? - Dim ridesBusToWork3 As Nullable(Of Boolean) \ No newline at end of file diff --git a/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_2.vb b/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_2.vb deleted file mode 100644 index 1428885a3d883..0000000000000 --- a/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_2.vb +++ /dev/null @@ -1 +0,0 @@ - Dim numberOfChildren? As Integer \ No newline at end of file diff --git a/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_3.vb b/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_3.vb deleted file mode 100644 index 49cd3faf0e43e..0000000000000 --- a/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_3.vb +++ /dev/null @@ -1 +0,0 @@ - numberOfChildren = 2 \ No newline at end of file diff --git a/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_4.vb b/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_4.vb deleted file mode 100644 index 2ef5c4e23c55d..0000000000000 --- a/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_4.vb +++ /dev/null @@ -1 +0,0 @@ - numberOfChildren = Nothing \ No newline at end of file diff --git a/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_5.vb b/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_5.vb deleted file mode 100644 index d66d1ad7af014..0000000000000 --- a/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_5.vb +++ /dev/null @@ -1,5 +0,0 @@ - If numberOfChildren.HasValue Then - MsgBox("There are " & CStr(numberOfChildren) & " children.") - Else - MsgBox("It is not known how many children there are.") - End If \ No newline at end of file diff --git a/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_6.vb b/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_6.vb deleted file mode 100644 index 90c0aba90eb4e..0000000000000 --- a/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_6.vb +++ /dev/null @@ -1,18 +0,0 @@ - Dim b1? As Boolean - Dim b2? As Boolean - b1 = True - b2 = Nothing - - ' The following If statement displays "Expression is not true". - If (b1 And b2) Then - Console.WriteLine("Expression is true") - Else - Console.WriteLine("Expression is not true") - End If - - ' The following If statement displays "Expression is not false". - If Not (b1 And b2) Then - Console.WriteLine("Expression is false") - Else - Console.WriteLine("Expression is not false") - End If \ No newline at end of file diff --git a/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_7.vb b/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_7.vb deleted file mode 100644 index c1e517c4de917..0000000000000 --- a/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_7.vb +++ /dev/null @@ -1,12 +0,0 @@ - ' Variable n is a nullable type, but both m and n have proper values. - Dim m As Integer = 3 - Dim n? As Integer = 2 - - ' The comparison evaluated is 3>2, but compare1 is inferred to be of - ' type Boolean?. - Dim compare1 = m > n - ' The values summed are 3 and 2, but sum1 is inferred to be of type Integer?. - Dim sum1 = m + n - - ' The following line displays: 3 * 2 * 5 * True - Console.WriteLine(m & " * " & n & " * " & sum1 & " * " & compare1) \ No newline at end of file diff --git a/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_8.vb b/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_8.vb deleted file mode 100644 index 83d3d1a1e5c05..0000000000000 --- a/docs/visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_8.vb +++ /dev/null @@ -1,9 +0,0 @@ - ' Change the value of n to Nothing. - n = Nothing - - Dim compare2 = m > n - Dim sum2 = m + n - - ' Because the values of n, compare2, and sum2 are all Nothing, the - ' following line displays 3 * * * - Console.WriteLine(m & " * " & n & " * " & sum2 & " * " & compare2) \ No newline at end of file diff --git a/docs/visual-basic/programming-guide/language-features/data-types/nullable-value-types.md b/docs/visual-basic/programming-guide/language-features/data-types/nullable-value-types.md index b4e89745c7b91..4cdbc90b7d1e8 100644 --- a/docs/visual-basic/programming-guide/language-features/data-types/nullable-value-types.md +++ b/docs/visual-basic/programming-guide/language-features/data-types/nullable-value-types.md @@ -1,10 +1,7 @@ --- title: "Nullable Value Types (Visual Basic)" -ms.custom: "" ms.date: 07/20/2015 ms.prod: .net -ms.reviewer: "" -ms.suite: "" ms.technology: - "devlang-visual-basic" ms.topic: "article" @@ -17,7 +14,6 @@ helpviewer_keywords: - "nullable types [Visual Basic]" - "data types [Visual Basic], nullable" ms.assetid: 9ac3b602-6f96-4e6d-96f7-cd4e81c468a6 -caps.latest.revision: 23 author: dotnet-bot ms.author: dotnetcontent --- @@ -26,7 +22,7 @@ Sometimes you work with a value type that does not have a defined value in certa Each nullable type is constructed from the generic structure. Consider a database that tracks work-related activities. The following example constructs a nullable `Boolean` type and declares a variable of that type. You can write the declaration in three ways: - [!code-vb[VbVbalrNullableValue#1](../../../../visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_1.vb)] + [!code-vb[VbVbalrNullableValue#1](../../../../../samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbalrNullableValue/VB/Class1.vb#1)] The variable `ridesBusToWork` can hold a value of `True`, a value of `False`, or no value at all. Its initial default value is no value at all, which in this case could mean that the information has not yet been obtained for this person. In contrast, `False` could mean that the information has been obtained and the person does not ride the bus to work. @@ -40,18 +36,18 @@ Sometimes you work with a value type that does not have a defined value in certa ### Default Values When you declare a variable with a nullable type, its property has a default value of `False`. This means that by default the variable has no defined value, instead of the default value of its underlying value type. In the following example, the variable `numberOfChildren` initially has no defined value, even though the default value of the `Integer` type is 0. - [!code-vb[VbVbalrNullableValue#2](../../../../visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_2.vb)] + [!code-vb[VbVbalrNullableValue#2](../../../../../samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbalrNullableValue/VB/Class1.vb#2)] A null value is useful to indicate an undefined or unknown value. If `numberOfChildren` had been declared as `Integer`, there would be no value that could indicate that the information is not currently available. ### Storing Values You store a value in a variable or property of a nullable type in the typical way. The following example assigns a value to the variable `numberOfChildren` declared in the previous example. - [!code-vb[VbVbalrNullableValue#3](../../../../visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_3.vb)] + [!code-vb[VbVbalrNullableValue#3](../../../../../samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbalrNullableValue/VB/Class1.vb#3)] If a variable or property of a nullable type contains a defined value, you can cause it to revert to its initial state of not having a value assigned. You do this by setting the variable or property to `Nothing`, as the following example shows. - [!code-vb[VbVbalrNullableValue#4](../../../../visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_4.vb)] + [!code-vb[VbVbalrNullableValue#4](../../../../../samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbalrNullableValue/VB/Class1.vb#4)] > [!NOTE] > Although you can assign `Nothing` to a variable of a nullable type, you cannot test it for `Nothing` by using the equal sign. Comparison that uses the equal sign, `someVar = Nothing`, always evaluates to `Nothing`. You can test the variable's property for `False`, or test by using the `Is` or `IsNot` operator. @@ -59,7 +55,7 @@ Sometimes you work with a value type that does not have a defined value in certa ### Retrieving Values To retrieve the value of a variable of a nullable type, you should first test its property to confirm that it has a value. If you try to read the value when is `False`, Visual Basic throws an exception. The following example shows the recommended way to read the variable `numberOfChildren` of the previous examples. - [!code-vb[VbVbalrNullableValue#5](../../../../visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_5.vb)] + [!code-vb[VbVbalrNullableValue#5](../../../../../samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbalrNullableValue/VB/Class1.vb#5)] ## Comparing Nullable Types When nullable `Boolean` variables are used in Boolean expressions, the result can be `True`, `False`, or `Nothing`. The following is the truth table for `And` and `Or`. Because `b1` and `b2` now have three possible values, there are nine combinations to evaluate. @@ -78,7 +74,7 @@ Sometimes you work with a value type that does not have a defined value in certa When the value of a Boolean variable or expression is `Nothing`, it is neither `true` nor `false`. Consider the following example. - [!code-vb[VbVbalrNullableValue#6](../../../../visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_6.vb)] + [!code-vb[VbVbalrNullableValue#6](../../../../../samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbalrNullableValue/VB/Class1.vb#6)] In this example, `b1 And b2` evaluates to `Nothing`. As a result, the `Else` clause is executed in each `If` statement, and the output is as follows: @@ -92,14 +88,14 @@ Sometimes you work with a value type that does not have a defined value in certa ## Propagation If one or both of the operands of an arithmetic, comparison, shift, or type operation is nullable, the result of the operation is also nullable. If both operands have values that are not `Nothing`, the operation is performed on the underlying values of the operands, as if neither were a nullable type. In the following example, variables `compare1` and `sum1` are implicitly typed. If you rest the mouse pointer over them, you will see that the compiler infers nullable types for both of them. - [!code-vb[VbVbalrNullableValue#7](../../../../visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_7.vb)] + [!code-vb[VbVbalrNullableValue#7](../../../../../samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbalrNullableValue/VB/Class1.vb#7)] If one or both operands have a value of `Nothing`, the result will be `Nothing`. - [!code-vb[VbVbalrNullableValue#8](../../../../visual-basic/programming-guide/language-features/data-types/codesnippet/VisualBasic/nullable-value-types_8.vb)] + [!code-vb[VbVbalrNullableValue#8](../../../../../samples/snippets/visualbasic/VS_Snippets_VBCSharp/VbVbalrNullableValue/VB/Class1.vb#8)] ## Using Nullable Types with Data - A database is one of the most important places to use nullable types. Not all database objects currently support nullable types, but the designer-generated table adapters do. See "TableAdapter Support for Nullable Types" in [TableAdapter Overview](/visualstudio/data-tools/tableadapter-overview). + A database is one of the most important places to use nullable types. Not all database objects currently support nullable types, but the designer-generated table adapters do. See "TableAdapter Support for Nullable Types" in [TableAdapter Overview](/visualstudio/data-tools/tableadapter-overview). ## See Also