473,938 Members | 3,121 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("BM W", "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 1280
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("BM W", "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.co m>
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..jwaon line..com
-----------------------------------------------------------------------
"NuB" <me@m.com> wrote in message news:ea******** ******@TK2MSFTN GP10.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("BM W", "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("BM W");
CarMake.Add("Le xus");

*or*

CarMake.AddRang e(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*********@do tcomdatasolutio ns.com> wrote in message
news:eE******** ******@TK2MSFTN GP10.phx.gbl...
A few notes inline >>

--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"NuB" <me@m.com> wrote in message
news:ea******** ******@TK2MSFTN GP10.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("BM W", "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("BM W");
CarMake.Add("Le xus");

*or*

CarMake.AddRang e(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
11613
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 below. I run through the For Each loop 5 times and I place a reference to the object in an ArrayList. Once I skip out of the loop block I expect to have 5 different instances of that class in the ArrayList. However, instead I have 5 instances of...
2
369
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 required values as needed and setting them to the relevant property within my object. The reading of the xml file works as it should. I get a problem when I try to add the object that I created to the arraylist. It seems to be adding each one,...
4
5498
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 dropdownlist to the screen for selection. This continues until there are no children, and then it checks for a help article list based on that last selection and displays actual articles for display. Adding the controls and getting everything...
1
2653
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> vVector to it.. I'm using this line of code.. alValue->Add (new System::Double(vVector)) and I'm getting the following compilation error..
2
2451
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 the Columns dialog box from the properties of the datagrid, on the left that contains a select button. So now, when you press the button the whole row is highlighted. Now, what I want to do is have the user highlight as many rows as they wish...
2
1924
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 item I press buttton with ibNewDep_Click event. After that the grid is in edit state and I can modify new item, it has some text, set as default - "<nowy wydział>". But - this is the weirdness - when I add some text following the default value
47
3934
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 say, C programs consist of variables to store the input and functions to manipulate them. This would make C object-oriented - how cool would that be? Are there any problems with adding the ability to have functions
5
2385
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 do this. Or is there a way to find out how many things are actually in an array without it counting the null sections? Say I have an array but only have 5 things in there how can I easily find out that there are 5?
2
3382
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(); private SQLiteConnection cn; private SQLiteDataAdapter adapterMacros; cn = new SQLiteConnection("Data Source = irDatabase.db3"); SQLiteCommand commandMacros = new SQLiteCommand(); commandMacros.CommandText = "SELECT * FROM irMacros"; adapterMacros =...
0
11515
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11099
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11282
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10652
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9854
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7377
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4900
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4442
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3495
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.