我想从只读属性中获取几个值。下面是我的代码
Public Class Class1
ReadOnly Property Ca As New Class2
End Class
Public Class Class2
ReadOnly Property getass(q As Integer, ww As String) As Integer
Get
Codes that return q And ww
End Get
End Property
End Class
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim a As New Class1
Dim ret As Integer
Dim qq As Integer = Nothing
Dim qqq As String = Nothing
ret = a.Ca.getass(qq, qqq)
End Sub
End Class
我想终于得到qq = q和qqq = ww ... 感谢
答案 0 :(得分:1)
您不想为此目的使用财产。
相反,只需声明一个修改传递参数的Sub,如下所示:
Public Class Class2
Sub getass(ByRef q As Integer, ByRef ww As String)
Dim _q as Integer
Dim _w as String
'do whatever you want
'then assign the final values and end sub
q = _q
ww = _ww
End Sub
End Class
然后像这样使用sub:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim a As New Class1
Dim qq As Integer = Nothing
Dim qqq As String = Nothing
a.Ca.getass(qq, qqq)
'At this point your local qq and qqq will have the value setted by the getass Sub
End Sub
End Class
请注意,这不是一个好的设计模式,以表明您拥有学生证和姓名的最终意图。
考虑创建一个Class" Student"拥有你想要的所有属性并制作Class2(我可以假设是一个教室或类似的东西)返回一个"学生"对象
或者您可以使用KeyValuePair结构
编辑: 如果您仍想通过界面执行此操作,请尝试以下操作:
Public Class Class2
Public ReadOnly Property getass(ByRef q As Integer, ByRef ww As String) as Integer
Get
Dim _q as Integer
Dim _w as String
'do whatever you want
'then assign the final values and end sub
q = _q
ww = _ww
return ID 'ID is what you want (Integer)
End Get
End Property
End Class