VB 2010 (7) 引用类型

Object 类

https://docs.microsoft.com/zh-cn/dotnet/api/system.object?view=netframework-4.8

Object类是.NET中每个类型的基类——包括值类型和引用类型。本质上,每个变量都是一个对象,都可以作为对象来处理。

由于Object类是所有类型的基础,所以可以将任何变量转换为Object。引用类型将维护它们当前的引用和实现代码,但是会被当做一般类型来处理,而值类型会从它们在堆栈的当前位置上提取,并放入堆上与Object相关的内存位置中。这个过程称为“装箱”,因为我们提取了值,并把它从一个地方移动到另一个地方。

    String 类

https://docs.microsoft.com/zh-cn/dotnet/api/system.string?view=netframework-4.8

    String.Empty 字段

String类是.NET中特有的,这是唯一不是值类型的基本类型。

    String.Compare 方法

https://docs.microsoft.com/zh-cn/dotnet/api/system.string.compare?view=netframework-4.8

    String.CompareOrdinal 方法

https://docs.microsoft.com/zh-cn/dotnet/api/system.string.compareordinal?view=netframework-4.8#System_String_CompareOrdinal_System_String_System_String_

    String.Concat 方法

https://docs.microsoft.com/zh-cn/dotnet/api/system.string.concat?view=netframework-4.8#System_String_Concat_System_String_System_String_System_String_System_String_

    String.Copy(String) 方法

https://docs.microsoft.com/zh-cn/dotnet/api/system.string.copy?view=netframework-4.8

    String.Equals 方法

https://docs.microsoft.com/zh-cn/dotnet/api/system.string.equals?view=netframework-4.8#definition

    String.IsNullOrEmpty(String) 方法

https://docs.microsoft.com/zh-cn/dotnet/api/system.string.isnullorempty?view=netframework-4.8#System_String_IsNullOrEmpty_System_String_

    String.Substring 方法

https://docs.microsoft.com/zh-cn/dotnet/api/system.string.substring?view=netframework-4.8#System_String_Substring_System_Int32_

    String.Split 方法

https://docs.microsoft.com/zh-cn/dotnet/api/system.string.split?view=netframework-4.8#definition

    String.Concat 方法

https://docs.microsoft.com/zh-cn/dotnet/api/system.string.concat?view=netframework-4.8#definition

    StringBuilder 类

https://docs.microsoft.com/zh-cn/dotnet/api/system.text.stringbuilder?view=netframework-4.8

 

DBNull 类

https://docs.microsoft.com/zh-cn/dotnet/api/system.dbnull?view=netframework-4.8

 

Array 类

https://docs.microsoft.com/zh-cn/dotnet/api/system.array?view=netframework-4.8

 

System.Collections 命名空间

https://docs.microsoft.com/zh-cn/dotnet/api/system.collections?view=netframework-4.8

 

CType 函数 (Visual Basic)

返回将表达式显式转换为指定的数据类型、对象、结构、类或接口的结果

https://docs.microsoft.com/zh-cn/dotnet/visual-basic/language-reference/functions/ctype-function

VB 2010 (7) 引用类型

Public Class Form1
    Dim count As Integer
    Private Sub ButtonTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonTest.Click
        count += 1
        'MessageBox.Show("Hello World show " & count.ToString & " times", _
        '                "Hello World message box", _
        '                MessageBoxButtons.OK, _
        '                MessageBoxIcon.Information)
        '测试值类型
        'ValueType()

        '测试引用类型
        'RefType()

        '试验布尔型数据
        'Booltest()

        '试验时间数据类型
        'Dates()

        '试验String类型
        StringSamples()
    End Sub
    '测试值类型
    Private Sub ValueType()
        Dim ptX As Point = New Point(10, 20)
        Dim ptY As Point
        ptY = ptX
        'ptX变,ptY不会变
        ptX.X = 200
        TextBox1.Text = "值类型变量:" & vbCrLf & "Pt Y= " & ptY.ToString & vbCrLf
    End Sub
    '测试引用类型
    Private Sub RefType()
        Dim objX As System.Text.StringBuilder = New System.Text.StringBuilder("Hello World.")
        Dim objY As System.Text.StringBuilder
        objY = objX
        'objX变化,objY也会变,浅复制(shallow copy)
        objX.Replace("World", "Test")
        TextBox1.Text = TextBox1.Text & "引用型变量:" & vbCrLf & "objY = " & objY.ToString
    End Sub
    '试验布尔型数据
    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
    '时间类型
    Private Sub Dates()
        Dim dtNow = Now
        Dim dtToday = Today
        TextBox1.Text = dtNow & Environment.NewLine
        TextBox1.Text &= dtToday.ToShortDateString & Environment.NewLine
        TextBox1.Text &= DateTime.UtcNow & Environment.NewLine
        Dim dtString = #12/13/2009#
        TextBox1.Text &= dtString.ToLongDateString
    End Sub

    '试验String类型
    Private Sub stringSamples()
        Dim strSample As String = "ABC"
        Dim strSample2 = "DEF"
        Dim strSample3 = New String("A"c, 20) '调用构造函数,第一个参数是一个字符,第二个是字符串中该字符的重复次数
        Dim strline = New String("-", 80)

        '子串
        Dim MysubString = "Hello World"
        TextBox1.Text &= MysubString.Substring(0, 5) & Environment.NewLine '起始位置及长度
        TextBox1.Text &= MysubString.Substring(6) & Environment.NewLine '起始位置到末尾
        TextBox1.Text &= strline & Environment.NewLine

        '分隔
        Dim csvString = "Col1,Col2,Col3"
        Dim stringArray As String() = csvString.Split(",")
        For i = 0 To stringArray.Length - 1
            TextBox1.Text &= stringArray(i) & Environment.NewLine
        Next
        TextBox1.Text &= strline & Environment.NewLine

        '字符串连接
        Dim start = Now
        Dim strRedo = "A simple string "
        For index = 1 To 10000
            strRedo &= "Making a much larger String."
        Next
        'DateTime.Subtract方法返回通过从此实例的值减去指定的时间或持续时间得到的值。
        TextBox1.Text &= "time to Concatenate strings:" & _
            (Now().Subtract(start)).TotalMilliseconds().ToString() & _
            " String length:" & strRedo.Length.ToString
        TextBox1.Text &= strline & Environment.NewLine

        start = Now
        Dim strBulider = New System.Text.StringBuilder("A simple string ")
        For Index = 1 To 1000000
            strBulider.Append("Making a much larger string")
        Next
        TextBox1.Text &= "Time to concatenate string:" & _
            (Now().Subtract(start)).TotalMilliseconds().ToString() & _
            " String length:" & strBulider.Length.ToString
        TextBox1.Text &= strline & Environment.NewLine


    End Sub
End Class