Vb.net 为什么这次搬迁的实施会有相应的工作?

Vb.net 为什么这次搬迁的实施会有相应的工作?,vb.net,Vb.net,因为三是只读的,并且依赖于非属性(四)。三个应该是未定义的。 道具(不设置四个)如何将三个设置为正确的值 public sub main Dim x1 = New one, x2 = New two x1.one = 3 MoveCorresponding(x1, x2) end sub Public Sub MoveCorresponding(a As Object, b As Object, Optional ignoreList As List(Of String

因为三是只读的,并且依赖于非属性(四)。三个应该是未定义的。
道具(不设置四个)如何将三个设置为正确的值

public sub main
    Dim x1 = New one, x2 = New two
    x1.one = 3
    MoveCorresponding(x1, x2)
end sub

Public Sub MoveCorresponding(a As Object, b As Object, Optional ignoreList As List(Of String) = Nothing)
    Dim oType As Type = b.GetType
    Dim iType = a.GetType
    Dim props = iType.GetProperties()
    For Each pInf As PropertyInfo In props
        Dim parName = pInf.Name
        If pInf.CanWrite Then
            Try
                Dim val = pInf.GetValue(a, Nothing)
                pInf.SetValue(b, val)
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End If
    Next

End Sub

End Class

Class one
    Public Property one As String = "1"
    Dim four As Integer = 1
    Public ReadOnly Property three As Integer
        Get
            Return four * 10
        End Get
    End Property

End Class

您在声明的同一行上设置了四个:

Dim four As Integer = 1 '<-- see?  it's set to "1".

我不明白你的问题吗?

这不是在回答问题。 但是为什么要写这样的代码呢

这令人困惑

dim four as integer = 1 ' <=== But why? Why use four as object name but hold 1 as it's value??

dim four as integer=1'这应该是问题下的注释,而不是答案。
dim four as integer = 1 ' <=== But why? Why use four as object name but hold 1 as it's value??