473,408 Members | 2,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Class in arraylist

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
4 1217
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
"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
Herfried- good question, LOL I pulled the code from a msdn article.
Nov 21 '05 #4
Herfried- good question, LOL I pulled the code from a msdn article.
Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Pure Krome | last post by:
How do i serialize two instances (of some object) in the same class? I'm not sure how i would de-serialize a class that has two or more instances of some object type, and how the deserialize...
3
by: David | last post by:
hello... a want to create my own collection class... i tryed it two ways, one then declarinf it as of IList interface (not easy way) and like an ArrayList derived class (easy way) in both...
2
by: David | last post by:
Hi all, I am fairly new to C#. so go easy on me :-) Anyhow, I have a class file that I have set up properties and a method. I am calling this class file directly from and aspx.cs file. So...
1
by: leal ting | last post by:
a class inherited from ArrayList, is saved to ViewState, why the type of the object read from ViewSate is not the class, but the parent, ArrayList lealting@hotmail.com] the class inherited...
16
by: Dennis | last post by:
I have a class named "myclass" and an arraylist containing elements of type "MyClass". I want to get the value of a property of "MyClass" (a string type) for one of the arraylist elements. I...
9
by: David A. Osborn | last post by:
I have a set of classes that each have an enumeration in them, and based on dynamic input I need to access a different enumeration. For example Three classes Class_A, Class_B, and Class_C that...
16
by: Allen | last post by:
I have a class that returns an arraylist. How do I fill a list box from what is returned? It returns customers which is a arraylist but I cant seem to get the stuff to fill a list box. I just...
0
by: jeytu | last post by:
Hi all, I'm a newbie with .net. I have created a web method that would return a class. The definition of the class is <Serializable()> Public Class Response Dim l_status As Boolean ...
14
by: budy_ludy | last post by:
Hi All, I am new to vb .net, I have an ArrayList and i store class objects in it, and later i want to retrieve each ArrayList items and type cast to the class, How can it be done ? I used...
1
by: bjwillykajilly | last post by:
Well, I got an assignment due this morning, so i guess ill end up turning it in a day late eh. anyways. I have a couple problems that I don't know what to do with. the objective is here: Write a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.