TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Simon
NA
1
0
Confused with ArrayList and Reference types
Sep 4 2008 11:49 AM
I have a custom object, EventList that extends ArrayList, and a second custom object, Event, that stores event information and has a constructor that can take a database ID to instantiate itself.
I am trying to write a method for the EventList to fill it with a list of Event objects instantiated from a database.
I am using the following loop
while
(dbManager.DataReader.Read())
{
int
intEventID = (
int
) dbManager.DataReader["EventID"] ;
this
.Add(
new
Event
( intEventID ) );
}
However the
this
.Add(...)
line seems to be updating a reference to the previously added Event Object rather than creating a new instance of an Event object. I am ending up with an array list with a number of references to the same Event object!
Can anyone shed any light on why this is happening, and how I can get around it?
Reply
Answers (
1
)
Need help on using System.Collections.Generic
random selection from an array