MDA MDA - 25 days ago 6
Vb.net Question

property return sevral value

I want to get several value from a read only property.in Below is my code

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


I want finally get qq=q and qqq=ww...
thanks

Answer

You don't want to use a Property for this purpose.

Instead just declare a Sub that modifies the passed parameters like this:

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

Then use the sub like this:

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

Please consider that this is not a good design pattern for your final intent of having a student ID and Name.

Consider creating a Class "Student" with all the properties you want and make Class2 (I can suppose is a classroom or something like that) return a "Student" object.

Or you could use a KeyValuePair structure

EDIT: If you still want to do this through an interface try this:

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