开发者

What kind of array is Foo() as Foo()?

开发者 https://www.devze.com 2023-01-27 23:51 出处:网络
We generated a class from an XML file a while back. I think we used xsd.exe. One of the main node collections in the XML file was rendered as:

We generated a class from an XML file a while back. I think we used xsd.exe.

One of the main node collections in the XML file was rendered as:

<System.Xml.Serialization.XmlElementAttribute("PRODUCT")>  _
Public Property PRODUCT() As PRODUCT()
    Get
        Return Me.pRODUCTField
    End Get
    Set
        Me.pRODUCTField = value
    End Set
End Property

And sure, there's PRODUCT class defined later on, and it worked fine. Serialized and deserialized fine. Didn't need to worry about it o开发者_如何学运维r manipulate it.

Only now we have to revisit and manipulate the data.

But what kind of collection (array?) is Public Property PRODUCT() As PRODUCT(), and how do we loop over it? And add to it?

Basic question, I know. Probably got too comfortable with generics and now xsd has thrown something at me which isn't List(of T) I'm running scared.


Don't be confused by the two sets of parens there. The first set, is simply the parens after the name of the property, whereas the second identifies the return type as an array of Product objects.

Similar to: Public Property IDs() As Integer()

That property returns only an array of integers, and the parens near IDs() only exist because you're declaring the property.

Since it appears to be a standard array of Product objects, you can loop over it with any number of normal loops:

For Each p As PRODUCT In obj.PRODUCTS()
   ...
Next

or

For i As Integer = 0 To obj.PRODUCTS.Length-1
   ...
Next i


Your code

Public Property PRODUCT() as PRODUCT()

Returns an array of Objects Of Type PRODUCT. Now whether that Type is a Collection, Structure, or Array I do not know with the code you have provided. The simplest way to loop over it would be as such.

For each prod as PRODUCT in rtnPRODUCTS
   'Do Something
Next
0

精彩评论

暂无评论...
验证码 换一张
取 消