如何创建这个类

时间:2011-08-19 13:54:23

标签: vb.net xsd

我有一个从vb.net2010中的XSD文件创建的类<​​/ p>

Partial Public Class responseOperation

    Private attributeField() As attribute

    Public Property attribute() As attribute()
        Get
            Return Me.attributeField
        End Get
        Set(ByVal value As attribute())
            Me.attributeField = value
        End Set
    End Property

如何实例化或填充属性类,其中属性类为

Partial Public Class attribute

    Private nameField As String

    Private valueField As String

    Public Property name() As String
        Get
            Return Me.nameField
        End Get
        Set(ByVal value As String)
            Me.nameField = value
        End Set
    End Property

    Public Property value() As String
        Get
            Return Me.valueField
        End Get
        Set(ByVal value As String)
            Me.valueField = value
        End Set
    End Property
End Class

我跑的时候

 xml_req_obj.attribute(0).value = "abcd"
 xml_req_obj.attribute(0).name =  "efg"

我得到运行时错误,因为我正在为未创建的类分配内容

这似乎是一项微不足道的任务 如果有人能告诉我如何创建这个对象并将数据传递给属性属性

三江源 汉森

1 个答案:

答案 0 :(得分:0)

您没有实例化数组或数组项。

尝试

Private attributeField() As attribute = New attribute(20)

xml_req_obj.attribute(0) = New Attribute()
xml_req_obj.attribute(0).value = "abcd"
xml_req_obj.attribute(0).name =  "efg"