What did VB replace the function “Set” with?

前端 未结 3 1736
慢半拍i
慢半拍i 2020-12-19 02:43

I\'ve found several aspx codes for forms which include the use of a \"Set\" function. When I try them out on the hosting server, I get an error message that \"Set is no lon

3条回答
  •  悲&欢浪女
    2020-12-19 03:26

    Set is a keyword in VB6, with the intrudction of VB.NET the keyword, as used in this context, was removed.

    Formerly, Set was used to indicate that an object reference was being assigned (Let was the default). Because default properties no longer are supported unless they accept parameters, these statements have been removed.

    Module Module1
        Sub Main()
    
        Dim person As New Person("Peter")
        Dim people As New People()
    
        people.Add(person)
    
        'Use the default property, provided we have a parameter'
    
        Dim p = people("Peter")
    
        End Sub
    End Module
    
    Public Class People
        Private _people As New Dictionary(Of String, Person)
    
        Public Sub Add(ByVal person As Person)
        _people.Add(person.Name, person)
        End Sub
    
        Default Public ReadOnly Property Person(ByVal name As String) As Person
        Get
            Return _people(name)
        End Get
        End Property
    End Class
    
    Public Class Person
        Private _name As String
    
        Public Sub New(ByVal name As String)
        _name = name
        End Sub
    
        Public ReadOnly Property Name() As String
        Get
            Return _name
        End Get
        End Property
    End Class
    

提交回复
热议问题