标题:有人能详解下 get ... end get set ... end set 语句的详细调用过程及使用 ...
取消只看楼主
moou
Rank: 2
等 级:论坛游民
威 望:1
帖 子:22
专家分:40
注 册:2018-8-15
结帖率:0
 问题点数:0 回复次数:2 
有人能详解下 get ... end get set ... end set 语句的详细调用过程及使用原理之类的吗?新手不是很理解这个函数,谢谢!MSDN
程序代码:
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
搜索更多相关主题的帖子: get end set Value space 
2018-10-17 15:48
moou
Rank: 2
等 级:论坛游民
威 望:1
帖 子:22
专家分:40
注 册:2018-8-15
得分:0 
再加一个示例:

程序代码:
    '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
2018-10-17 16:02
moou
Rank: 2
等 级:论坛游民
威 望:1
帖 子:22
专家分:40
注 册:2018-8-15
得分:0 
回复 3楼 lgwd
看了不少,不是特别理解,所以才来论坛咨询一下
2018-12-03 16:40



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-490466-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.179051 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved