|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Using a Structure in a ClassI'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 ValuationStructure 'another structure End Structure And the class I'm creating looks like: Public Class Report Private _ID As Integer Private _ValuationResult As myWebservice.ValuationResult 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.ValuationResult Get Return _ValuationResult End Get Set(ByVal Value as myWebservice.ValuationResult) _ValuationResult = 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.ValuationResult) ValuationResult = New myWebservice.ValuationResult Me.ValuationResult.Reliability = Result.Reliability Me.ValuationResult.ShowClientID = Result.ShowClientID Me.ValuationResult.ShowDepartment = Result.ShowDepartment Me.ValuationResult.ShowSource = Result.ShowSource ValuationResult.Valuation = New myWebservice.Valuation Me.ValuationResult.Valuation.FSA = Result.Valuation.FSA Me.ValuationResult.Valuation.PID = Result.Valuation.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
Show quote
Hide quote
"Ren" <nospam@nospam.org> schrieb Maybe I didn't get the point, but why don't you simply write:> 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 ValuationStructure 'another structure > End Structure > > And the class I'm creating looks like: > > Public Class Report > Private _ID As Integer > Private _ValuationResult As myWebservice.ValuationResult > > 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.ValuationResult > Get > Return _ValuationResult > End Get > Set(ByVal Value as myWebservice.ValuationResult) > _ValuationResult = 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.ValuationResult) > > ValuationResult = New myWebservice.ValuationResult > > Me.ValuationResult.Reliability = Result.Reliability > Me.ValuationResult.ShowClientID = Result.ShowClientID > Me.ValuationResult.ShowDepartment = Result.ShowDepartment > Me.ValuationResult.ShowSource = Result.ShowSource > > ValuationResult.Valuation = New myWebservice.Valuation > > Me.ValuationResult.Valuation.FSA = Result.Valuation.FSA > Me.ValuationResult.Valuation.PID = Result.Valuation.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? Public Sub New(ByVal Result As myWebservice.ValuationResult) _ValuationResult = Result End Sub Armin Armin,
Thanks for your reply. I realized just as I hit "send" on my post that I could do as you suggested. What in the world was I thinking? Show quoteHide quote On Wed, 15 Feb 2006 17:17:02 +0100, "Armin Zingler" <az.nospam@freenet.de> wrote: >"Ren" <nospam@nospam.org> schrieb >> 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: >> >> <<snip>> >> Also, is this the best way of doing this? Is there another more >> elegant way? > > >Maybe I didn't get the point, but why don't you simply write: > >Public Sub New(ByVal Result As myWebservice.ValuationResult) > > _ValuationResult = Result > >End Sub > > > >Armin "Ren" <nospam@nospam.org> schrieb Too many trees to see the wood. Happens. :-)> Armin, > > Thanks for your reply. I realized just as I hit "send" on my post > that I could do as you suggested. What in the world was I > thinking? Armin
check point inside "cirkle" (basketball)
Exposing properties of a class within a class Unresponsive UI during lengthy operation ? Count lines in multi-line textbox Invoking a PictureBox click ? Can't Figure Out Correct Syntax MethodInfo or MethodBase? console.write Zoom in Cephalometric system Problems with Excel Object Library |
|||||||||||||||||||||||