Hi all,
I'm still rather new to .NET so I hope you'll bear with me as I try and explain
my question.
I am writing an ASP.NET application using VB.NET. I am accessing a web method
from a webservice that returns a structure. On the client side I have added the
webservice as a reference and created a class that contains the structure as a
member as well as some other variables. The structure looks something like:
Public Structure ValuationResult
Dim Reliability As Integer
Dim ShowClientID As String
Dim ShowDepartment As String
Dim ShowSource As String
Dim Valuation As ValuationStruct ure 'another structure
End Structure
And the class I'm creating looks like:
Public Class Report
Private _ID As Integer
Private _ValuationResul t As myWebservice.Va luationResult
Public Property ID as integer
Get
Return _ID
End Get
Set(ByVal Value As Integer)
_ID = Value
End Set
End Property
Public Property ValuationResult as myWebservice.Va luationResult
Get
Return _ValuationResul t
End Get
Set(ByVal Value as myWebservice.Va luationResult)
_ValuationResul t = Value
End Set
End Property
...
End Class
I am now trying to create a constructor that will allow the user to pass the
populated structure that I get back from the webservice and populate the
appropriate fields. After some trial and error I've come up with:
Public Sub New(ByVal Result As myWebservice.Va luationResult)
ValuationResult = New myWebservice.Va luationResult
Me.ValuationRes ult.Reliability = Result.Reliabil ity
Me.ValuationRes ult.ShowClientI D = Result.ShowClie ntID
Me.ValuationRes ult.ShowDepartm ent = Result.ShowDepa rtment
Me.ValuationRes ult.ShowSource = Result.ShowSour ce
ValuationResult .Valuation = New myWebservice.Va luation
Me.ValuationRes ult.Valuation.F SA = Result.Valuatio n.FSA
Me.ValuationRes ult.Valuation.P ID = Result.Valuatio n.PID
...
End Sub
Now this seems to work when I call the constructor but I am unclear exactly as
to why I need to call New for the structures and any structures contained within
the parent struct. Afterall, they are strucutures and not classes. Is it
because the struct is part of the class and no memory has yet been allocated for
it until I call New?
Also, is this the best way of doing this? Is there another more elegant way?
Thanks for your help.
Ren
I'm still rather new to .NET so I hope you'll bear with me as I try and explain
my question.
I am writing an ASP.NET application using VB.NET. I am accessing a web method
from a webservice that returns a structure. On the client side I have added the
webservice as a reference and created a class that contains the structure as a
member as well as some other variables. The structure looks something like:
Public Structure ValuationResult
Dim Reliability As Integer
Dim ShowClientID As String
Dim ShowDepartment As String
Dim ShowSource As String
Dim Valuation As ValuationStruct ure 'another structure
End Structure
And the class I'm creating looks like:
Public Class Report
Private _ID As Integer
Private _ValuationResul t As myWebservice.Va luationResult
Public Property ID as integer
Get
Return _ID
End Get
Set(ByVal Value As Integer)
_ID = Value
End Set
End Property
Public Property ValuationResult as myWebservice.Va luationResult
Get
Return _ValuationResul t
End Get
Set(ByVal Value as myWebservice.Va luationResult)
_ValuationResul t = Value
End Set
End Property
...
End Class
I am now trying to create a constructor that will allow the user to pass the
populated structure that I get back from the webservice and populate the
appropriate fields. After some trial and error I've come up with:
Public Sub New(ByVal Result As myWebservice.Va luationResult)
ValuationResult = New myWebservice.Va luationResult
Me.ValuationRes ult.Reliability = Result.Reliabil ity
Me.ValuationRes ult.ShowClientI D = Result.ShowClie ntID
Me.ValuationRes ult.ShowDepartm ent = Result.ShowDepa rtment
Me.ValuationRes ult.ShowSource = Result.ShowSour ce
ValuationResult .Valuation = New myWebservice.Va luation
Me.ValuationRes ult.Valuation.F SA = Result.Valuatio n.FSA
Me.ValuationRes ult.Valuation.P ID = Result.Valuatio n.PID
...
End Sub
Now this seems to work when I call the constructor but I am unclear exactly as
to why I need to call New for the structures and any structures contained within
the parent struct. Afterall, they are strucutures and not classes. Is it
because the struct is part of the class and no memory has yet been allocated for
it until I call New?
Also, is this the best way of doing this? Is there another more elegant way?
Thanks for your help.
Ren
Comment