[英]Object returning from Function vb.net
I'm trying to return an object from a function. 我正在尝试从函数返回一个对象。
Eg Ive got a function populateDog that returns Dog 例如,我有一个返回Dog的函数populateDog
So in my aspx class I want to be able to be able to pass in Lassie as the name of the dog(I have a dog class) and have the function return the object with the data it populated. 所以在我的aspx类中,我希望能够传入Lassie作为狗的名字(我有一个狗类)并让函数返回对象与它填充的数据。
So that in my aspx class i can go lassie.color, lassie.breed 所以在我的aspx类中我可以去lassie.color,lassie.breed
Main Goal is: lbl.txt = Lassie.Color 主要目标是:lbl.txt = Lassie.Color
Thanks 谢谢
EDIT 编辑
Public Function populateDog(ByVal dName As String) As dog
dbConnection()
Dim ObjDog As New dog(dName)
ObjDog.sBreed = "Collie"
Return ObjDog
End Function
The idea was to have a database and I would eventually pass in an ID to query results and return it. 我的想法是拥有一个数据库,我最终会传入一个ID来查询结果并返回它。 For now though I just wanna get this understanding and move forward.
现在虽然我只想获得这种理解并继续前进。
Public Function populateDog(ByVal dName As String) As dog
dbConnection()
Dim ObjDog As New dog(dName)
ObjDog.sBreed = "Collie"
ObjDog.Color = "White"
Return ObjDog
End Function
and 和
Dim Lassie as dog
Lassie = populateDog("Lassie")
lbl.Text = Lassie.Color
assuming your dog class is something like 假设你的狗课是类似的
Class dog
Public sBreed As String
Public Color As String
' other properties and functions
End Class
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.