Got to be an easier way...

W

Wardeaux

Hey all,
struggling to find an easier way to initialize an array of structures...
Structure room
Public Description as string
Public Refridge() as string
Public WeaponsVault() as string
end structure

Dim MyApt() as Room

I'd like to find a way similar to init an array of strings like:
Dim MyString() as String = {"str1","str2"}

Any assist is helpful...
wardeaux
 
J

José Joye

Hi,

Not too sure I undertood what you are looking for....

Here are my 2 Swiss cents ;-)

Structure room
Public Description As String
Public Refridge() As String
Public WeaponsVault() As String
Public Sub New(ByVal description As String, ByVal refridge() As String,
ByVal weaponsVault() As String)
Me.Description = description
Me.Refridge = refridge
Me.WeaponsVault = weaponsVault
End Sub
End Structure

Dim MyApt As New room("BlahBlah", New String() {"1", "2"}, New String()
{"3", "4"})


- José
 
H

Herfried K. Wagner [MVP]

Wardeaux said:
struggling to find an easier way to initialize an array of structures...
Structure room
Public Description as string
Public Refridge() as string
Public WeaponsVault() as string
end structure

Dim MyApt() as Room

I'd like to find a way similar to init an array of strings like:
Dim MyString() as String = {"str1","str2"}

\\\
Dim MyApt() As Room = {New Room(), New Room()}
///
 
R

Rob Nicholson

I'd like to find a way similar to init an array of strings like:
Dim MyString() as String = {"str1","str2"}

I don't tend to use Structure in VB.NET but they are pretty similar to
classes so I'd use something like this:

Module Module1

Sub Main()
Dim Rooms() As Room = _
{ _
New Room("Lounge", "Yes", "No"), _
New Room("Kitchen", "Bilko", "Womble") _
}
For Each Room As Room In Rooms
Console.WriteLine(Room.Description)
Next

End Sub

End Module

Public Class Room

Public Description As String
Public Refridge As String
Public WeaponsDefault As String

Sub New(ByVal Description As String, ByVal Refridge As String, ByVal
WeaponsDefault As String)
Me.Description = Description
Me.Refridge = Refridge
Me.WeaponsDefault = WeaponsDefault
End Sub

End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top