473,396 Members | 1,982 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,396 software developers and data experts.

adding to an arraylist

NuB
I need some help on this, I'm trying to add to an arrayList and its not
working

here is what i have
public ArrayList carMake
public ArrayList _CarMake { get { carMake; }
set( carMake = value; }}

and i'm adding this to the array List

carMake.Add("BMW", "Lexus", "GMC")

The cars are not being added to the list at all, when i run in debug mode
and step thru it I'm not seeing the values added. what i'm I missing?

Nov 17 '05 #1
3 1259
NuB <me@m.com> wrote:
I need some help on this, I'm trying to add to an arrayList and its not
working

here is what i have
public ArrayList carMake
public ArrayList _CarMake { get { carMake; }
set( carMake = value; }}

and i'm adding this to the array List

carMake.Add("BMW", "Lexus", "GMC")

The cars are not being added to the list at all, when i run in debug mode
and step thru it I'm not seeing the values added. what i'm I missing?


Well, for one thing there's no Add method in ArrayList which takes more
than one parameter, so that's clearly not your actual code.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
A few notes inline >>

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"NuB" <me@m.com> wrote in message news:ea**************@TK2MSFTNGP10.phx.gbl...
I need some help on this, I'm trying to add to an arrayList and its not working

here is what i have
public ArrayList carMake This should probably be private access (it's a backing field for a public property)
public ArrayList _CarMake { get { carMake; }
set( carMake = value; }} Framework standards are to use Pascal case (as you have) without an underscore prefix for public properties

and i'm adding this to the array List

carMake.Add("BMW", "Lexus", "GMC") Was the arraylist created before calling the Add method? Also, you can only add one item at a time using the Add() method.

Try the following:

private ArrayList carMake = new ArrayList(3); // 3 is initialize capacity, not length

public ArrayList CarMake { get { return carMake; } set { carMake = value; } }

[...]

CarMake.Add("BMW");
CarMake.Add("Lexus");

*or*

CarMake.AddRange(new object[] { "BMW", "Lexus", "GMC" });

The cars are not being added to the list at all, when i run in debug mode and step thru it I'm not seeing the values added. what
i'm I missing?


Nov 17 '05 #3
thanks dave that worked.
"Dave" <NO*********@dotcomdatasolutions.com> wrote in message
news:eE**************@TK2MSFTNGP10.phx.gbl...
A few notes inline >>

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"NuB" <me@m.com> wrote in message
news:ea**************@TK2MSFTNGP10.phx.gbl...
I need some help on this, I'm trying to add to an arrayList and its not
working

here is what i have
public ArrayList carMake

This should probably be private access (it's a backing field for a public
property)
public ArrayList _CarMake { get { carMake; }
set( carMake = value; }}

Framework standards are to use Pascal case (as you have) without an
underscore prefix for public properties

and i'm adding this to the array List

carMake.Add("BMW", "Lexus", "GMC")

Was the arraylist created before calling the Add method? Also, you can
only add one item at a time using the Add() method.

Try the following:

private ArrayList carMake = new ArrayList(3); // 3 is initialize
capacity, not length

public ArrayList CarMake { get { return carMake; } set { carMake =
value; } }

[...]

CarMake.Add("BMW");
CarMake.Add("Lexus");

*or*

CarMake.AddRange(new object[] { "BMW", "Lexus", "GMC" });

The cars are not being added to the list at all, when i run in debug mode
and step thru it I'm not seeing the values added. what i'm I missing?



Nov 17 '05 #4

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

Similar topics

2
by: Anchor | last post by:
Hi All, I was hoping someone could help me out. I am new to VB.NET and I don't know the language too well. I am trying to add an object instance of a class to an array like in the code snipet...
2
by: Vishal Somaiya | last post by:
Hello I am trying read from a xml file, pull the values in a object and then add the object to an ArrayList. I am using a 'while' loop to move through each node in the xml file and pulling the...
4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
1
by: San | last post by:
Hi, I'm using a Managed C++ project with MFC support. I have an ArrayList pointer object alValue (ArrayList* alValue) to this object i want to add all the elements present in Vector<double>...
2
by: Bob Hollness | last post by:
Hi group. I am a newbie to ASP.NET as you will see from some of the questions I may ask! I have a datagrid which I have populated from a database. It works great! I have added a column, via...
2
by: Tomek R. | last post by:
Hello ! I've got weird problem when adding new datagrid item. Here is the situation: my grid dgDeps is binded to DepartmentList arraylist, stored in Session between round-trips.. To add new...
47
by: Albert | last post by:
So structures are useful to group variables, so you can to refer to a collection as a single entity. Wouldn't it be useful to also have the ability to collect variable and functions? Ask K&R...
5
by: Extremest | last post by:
Is there a way to add new items to an arraylist witht he indexer? like with a normal array I can just do like array = new. What I have read with arraylist it will throw an exception if I try to...
2
by: canoewhiteh2o | last post by:
I am having trouble adding data columns to a disconnected database. I first load a datatable using: private DataTable dtMacros = new DataTable(); private ArrayList macro = new ArrayList();...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.