注册 登录
编程论坛 VB.NET论坛

有人能详解下 get ... end get set ... end set 语句的详细调用过程及使用原理之类的吗?新手不是很理解这个函数,谢谢!MSDN

moou 发布于 2018-10-17 15:48, 3419 次点击
程序代码:

Public Class Form1

    Dim firstName, lastName As String
    Public Property fullName() As String
        Get
            If lastName = "" Then
                Return firstName
            Else
                Return firstName & " " & lastName
            End If

        End Get
        Set(ByVal Value As String)
            Dim space As Integer = Value.IndexOf(" ")
            If space < 0 Then
                firstName = Value
                lastName = ""
            Else
                firstName = Value.Substring(0, space)
                lastName = Value.Substring(space + 1)
            End If
        End Set
    End Property

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        fullName = "Firstname LastName"
        MsgBox(fullName)
    End Sub
End Class
3 回复
#2
moou2018-10-17 16:02
再加一个示例:

程序代码:

    'txtEdit 是一个TextBox
    Public Property EditText() As String
        Get
            Return txtEdit.Text
        End Get
        Set(ByVal value As String)
            txtEdit.Text = value
        End Set
    End Property

    '使TextBox内的字符变成大写 这里EditText = EditText.ToUpper 返回到get set 是怎么个调用过程?
    Public Sub UpperCaseText()
        EditText = EditText.ToUpper
        StatusText = "The text is uppercase"
    End Sub
#3
lgwd2018-11-27 12:44
看看书,规定格式。要讲可是要费些笔墨,恐怕没有耐心!
#4
moou2018-12-03 16:40
回复 3楼 lgwd
看了不少,不是特别理解,所以才来论坛咨询一下
1