我正在尝试为我正在处理的项目创建一些简单的类。我遇到了循环引用的问题,我不确定这里的解决方案是什么。我理解我的课程可能设计错误,因此任何有关如何正确执行此操作的总体建议都将受到赞赏。
我将代码简化为最基本的内容,以显示我如何构建此类和引用。
"${arrayname[@]}"
当我运行此代码时,我收到错误:抛出了类型'System.StackOverflowException'的异常。
答案 0 :(得分:0)
而是在类中创建类,可以单独创建所有类。您可以使用以下代码:
Public Class Utilities
Dim myResult as Result
Public Shared Function Search(oInput As Contact) As ContactList
Dim oOutput As New ContactList
ReDim oOutput.Contact(500)
While oDataReader.Read()
oOutput.Success = True
oOutput.Contact(i) = New Contact()
oOutput.Contact(i).ID = oDataReader("ID").ToString()
oOutput.Contact(i).Created = oDataReader("Created").ToString()
oOutput.Contact(i).CreatedBy.ID = oDataReader("CreatedByID").ToString()
i = i + 1
End While
oDataReader.Close()
ReDim Preserve oOutput.Contact(i-1)
'you can store the array to myResult here for further use. and to reduce the Search function usage.
Return oOutput
End Function
End Class
Public Class Result : Inherits ContactList
Dim Success As Boolean = False
End Class
Public Class Customer
Dim myContact as Contact
Dim myContactList as ContactList
End Class
Public Class ContactList
Public Contact As Contact()
End Class
Public Class Contact
Public ID As String
Public Created As Date
Public CreatedBy As String
'CreatedBy should have Contact ID only as you are using the ID field of CreatedBy contact
'Where ever you are referencing the CreatedBy field you can have the ID string of the CreatedBy Contact
'On which you can lookup the data you needed.
Public Function setCreatedBy (_CreatedBy As String)
CreatedBy = _CreatedBy
End Function
End Class