By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,503 Members | 1,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,503 IT Pros & Developers. It's quick & easy.

Class in arraylist

P: n/a
I saw this example and was wondering how I would driectly assign
information out of this structure:

Public Class guitar
Private m_make As String
Private m_model As String
Private m_year As Short

Public Sub New(ByVal make, ByRef model, ByVal year)
m_make = make
m_model = model
m_year = year
End Sub
Public Property make() As String
Get
Return m_make
End Get
Set(ByVal Value As String)
m_make = Value
End Set
End Property
'<<<<<<<<<<<<<<<<<<<<<<<<<<<...Inset Other properties
here>>>>>>>>>>>>>>>>>>
End Class

Private al as New Arraylist()

al.Add(New guitar("Gibson", "Les Paul", 1958))
al.Add(New guitar("Fender", "Jazz Bass", 1964))
al.Add(New guitar("Guild", "Bluesbird", 1971))
So now if I want to grab and assign one of these values driectly from
the array list to another string how would I do that?
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Something like this:

Dim make as String = DirectCast(al.Item(0), guitar).make

Basically, you have guitar objects stored in your arraylist. You can iterate
through the arraylist to retrieve the various guitar objects. However, since
the Item property of the ArrayList returns an object, you'll need to cast it
to your guitar object before accessing the property of the guitar object
which is why the DirectCast above.

hope that helps..
Imran.
"Peter" <pe***@mclinn.com> wrote in message
news:dc*************************@posting.google.co m...
I saw this example and was wondering how I would driectly assign
information out of this structure:

Public Class guitar
Private m_make As String
Private m_model As String
Private m_year As Short

Public Sub New(ByVal make, ByRef model, ByVal year)
m_make = make
m_model = model
m_year = year
End Sub
Public Property make() As String
Get
Return m_make
End Get
Set(ByVal Value As String)
m_make = Value
End Set
End Property
'<<<<<<<<<<<<<<<<<<<<<<<<<<<...Inset Other properties
here>>>>>>>>>>>>>>>>>>
End Class

Private al as New Arraylist()

al.Add(New guitar("Gibson", "Les Paul", 1958))
al.Add(New guitar("Fender", "Jazz Bass", 1964))
al.Add(New guitar("Guild", "Bluesbird", 1971))
So now if I want to grab and assign one of these values driectly from
the array list to another string how would I do that?

Nov 21 '05 #2

P: n/a
"Peter" <pe***@mclinn.com> schrieb:
I saw this example and was wondering how I would driectly assign
information out of this structure:

Public Class guitar
Private m_make As String
Private m_model As String
Private m_year As Short

Public Sub New(ByVal make, ByRef model, ByVal year)


.... in addition to the other replies: Why is 'make' not declared 'As
String'? 'year' should be 'Short', and 'model' IMO doesn't need to be
passed 'ByRef'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #3

P: n/a
Herfried- good question, LOL I pulled the code from a msdn article.
Nov 21 '05 #4

P: n/a
Herfried- good question, LOL I pulled the code from a msdn article.
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.