Value types aren't as versatile as reference types, but they can provide better performance in many circumstances. The core value types (which include the majority of primitive types) are Boolean, Byte, Char, DateTime, Decimal, Double, Guid, Int16, Int32, Int64, SByte, Single, and TimeSpan. These are not the only value types, but rather the subset with which most Visual Basic developers consistently work. As you've seen, value types by definition store data on the stack.
Value types can also be referred to by their proper name: structures. The underlying principles and syntax of creating custom structures mirrors that of creating classes, covered in the next chapter. This section focuses on some of the built-in types provided by the .NET Framework — in particular, the built-in types known as primitives.
The .NET Boolean type represents true or false. Variables of this type work well with the conditional statements that were just discussed. When you declare a variable of type Boolean, you can use it within a conditional statement directly. Test the following sample by creating a Sub called BoolTest within ProVB2012_Ch03 (code file: MainWindow.xaml.vb):
Private Sub BoolTest() Dim blnTrue As Boolean = True Dim blnFalse As Boolean = False If (blnTrue) Then TextBox1.Text = blnTrue & Environment.NewLine TextBox1.Text &= blnFalse.ToString End If End Sub
The results of this code are shown in Figure 3.4. There are a couple things outside of the Boolean ...