G
Guest
I have found that in order to initiate an array of class objects I am having
to use a construct that I do not understand. The Class is defined as follows:
Public Class Prospects
Public Prospect_ID As String
Public Company_Name As String
Public Cust_Acct_Nbr As String
Public Salesperson_ID As String
Public Close_Probability As String
Public Est_Total_Rev As String
End Class 'Prospects
To make an array of such objects I am doing the following:
Dim ProspectList As Prospects() = New Prospects(0) {}
Then to populate the array I'm doing the following sort of thing:
i = 0
If myReader.Read Then
Do
If i > 0 Then
ReDim Preserve ProspectList(i)
End If
ProspectList(i) = New Prospects
If Not IsDBNull(myReader("Prospect_ID")) Then
ProspectList(i).Prospect_ID =
CStr(myReader("Prospect_ID"))
Else
ProspectList(i).Prospect_ID = "None"
End If
......... etc., et.
Then I make my return as follows:
Return ProspectList
This works. The array of prospect class objects gets returned to the web
service client.
Here is my question. What the heck do the curly brackets in the
Dim ProspectList As Prospects() = New Prospects(0) {}
statement do?
I assume they are a paramaterless constructor but to what do they serve as a
constructor? And why curly brackets? () will not work it has to be {}
Like I say, I've got it working but it drives me crazy when I don't
understand why something like this works.
Any insights would be appreciated.
to use a construct that I do not understand. The Class is defined as follows:
Public Class Prospects
Public Prospect_ID As String
Public Company_Name As String
Public Cust_Acct_Nbr As String
Public Salesperson_ID As String
Public Close_Probability As String
Public Est_Total_Rev As String
End Class 'Prospects
To make an array of such objects I am doing the following:
Dim ProspectList As Prospects() = New Prospects(0) {}
Then to populate the array I'm doing the following sort of thing:
i = 0
If myReader.Read Then
Do
If i > 0 Then
ReDim Preserve ProspectList(i)
End If
ProspectList(i) = New Prospects
If Not IsDBNull(myReader("Prospect_ID")) Then
ProspectList(i).Prospect_ID =
CStr(myReader("Prospect_ID"))
Else
ProspectList(i).Prospect_ID = "None"
End If
......... etc., et.
Then I make my return as follows:
Return ProspectList
This works. The array of prospect class objects gets returned to the web
service client.
Here is my question. What the heck do the curly brackets in the
Dim ProspectList As Prospects() = New Prospects(0) {}
statement do?
I assume they are a paramaterless constructor but to what do they serve as a
constructor? And why curly brackets? () will not work it has to be {}
Like I say, I've got it working but it drives me crazy when I don't
understand why something like this works.
Any insights would be appreciated.