Dear prob solver,
i have a problem with array lists. i am using array lists for adding objects. i just want to know, when you are adding an object to an arraylist whats the value u pass to the add method???
eg:
i have a class call vertex and i want to add an object from that class. so to add that object how to i add that to the arraylist??? do i need to pass the string id or pass an instant of the relevant class??? The code is below
vertex v;
string source_id
arraylist a = new arraylist();
a.add(source_id ??) or a.add(v)??? what is correct?
plz send me an answer asap... cz its for my final year project that i need to submit on next wek.. thnx aloot,,,,,,,,
Ran
5 1493
Dear prob solver,
i have a problem with array lists. i am using array lists for adding objects. i just want to know, when you are adding an object to an arraylist whats the value u pass to the add method???
eg:
i have a class call vertex and i want to add an object from that class. so to add that object how to i add that to the arraylist??? do i need to pass the string id or pass an instant of the relevant class??? The code is below
vertex v;
string source_id
arraylist a = new arraylist();
a.add(source_id ??) or a.add(v)??? what is correct?
plz send me an answer asap... cz its for my final year project that i need to submit on next wek.. thnx aloot,,,,,,,,
Ran
An array list can hold an array of any type of object that you would like.
for an array of strings you would do something like this. - string[] arrNames = {"Smith","Jones","Ryan"};
-
ArrayList a = new ArrayList();
-
for (int i = 0; i<arrNames.Length; i++)
-
{
-
a.Add(arrNames[i].Trim());
-
}
if you had an array of vertexes try something like this - object[] arrVertex = {vertex1, vertex2, vertex3};
-
ArrayList b = new ArrayList();
-
for(int i = 0; i<arrVertex.Length; i++)
-
{
-
b.Add(arrVertex[i]);
-
}
Give these examples a try and let us know if you encounter any other issues.
Nathan
Plater 7,872
Recognized Expert Expert
If you want to add the vertex object you would add an instance of it. -
vertex v;
-
string source_id
-
-
ArrayList a = new ArrayList();
-
//a.Add(source_id);
-
//or
-
//a.Add(v);<-this one
-
//??? what is correct?
-
You should note that any changes made to v after it was added to the ArrayList will not be reflected in the object stored. So make your changes first and do a .Add() after.
Can u plz check the below code and let me know whether its right or wrong???? i have a class called vertex and created an object of that class and those set methods are methods from the vertex class...is this code is correct??? what does that mean actually??? i wanted to know whether the desired operation happens throught this code
thnx aloooot...
ArrayList open_list= new ArrayList();
Vertex ObjvertID = new Vertex();
string[] arrayA= VerticesAdjecnt .ReturnAdjectVe rtArray(sourceI D);
for (int v = 0; v < arrayA.Length; v++)
{
ObjvertID.set_v ert_id(arrayA[v]);
ObjvertID.set_p arent_node_id(s ourceID);
open_list.Add(O bjvertID);
}
--------------------------------------------------------------------------------
Can u plz check the below code and let me know whether its right or wrong???? i have a class called vertex and created an object of that class and those set methods are methods from the vertex class...is this code is correct??? what does that mean actually??? i wanted to know whether the desired operation happens throught this code
thnx aloooot...
ArrayList open_list= new ArrayList();
Vertex ObjvertID = new Vertex();
string[] arrayA= VerticesAdjecnt .ReturnAdjectVe rtArray(sourceI D);
for (int v = 0; v < arrayA.Length; v++)
{
ObjvertID.set_v ert_id(arrayA[v]);
ObjvertID.set_p arent_node_id(s ourceID);
open_list.Add(O bjvertID);
}
If you want to add the vertex object you would add an instance of it. -
vertex v;
-
string source_id
-
-
ArrayList a = new ArrayList();
-
//a.Add(source_id);
-
//or
-
//a.Add(v);<-this one
-
//??? what is correct?
-
You should note that any changes made to v after it was added to the ArrayList will not be reflected in the object stored. So make your changes first and do a .Add() after.
ArrayList open_list= new ArrayList();
Vertex ObjvertID = new Vertex();
string[] arrayA= VerticesAdjecnt .ReturnAdjectVe rtArray(sourceI D);
for (int v = 0; v < arrayA.Length; v++)
{
ObjvertID.set_v ert_id(arrayA[v]);
ObjvertID.set_p arent_node_id(s ourceID);
open_list.Add(O bjvertID);
}
This looks like it should work just fine...? Although, you'll have to add a new declaration of your ObjvertID at the start of each loop... otherwise you might be getting funny problems with memory being shared between the objects in the ArrayList. So: -
ArrayList open_list= new ArrayList();
-
Vertex ObjvertID = new Vertex();
-
-
string[] arrayA= VerticesAdjecnt.ReturnAdjectVertArray(sourceID);
-
for (int v = 0; v < arrayA.Length; v++)
-
{
-
ObjvertID = new Vertex();
-
ObjvertID.set_vert_id(arrayA[v]);
-
ObjvertID.set_parent_node_id(sourceID);
-
open_list.Add(ObjvertID);
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Bo Peng |
last post by:
Dear list,
I am writing a Python extension module that needs a way to expose pieces
of a big C array to python. Currently, I am using NumPy like the following:
PyObject* res = PyArray_FromDimsAndData(1, int*dim, PyArray_DOUBLE,
char*buf);
Users will get a Numeric Array object and can change its values (and
actually change the underlying C array).
|
by: Kathryn |
last post by:
Hiya
I have a problem with using some client side and server side scripting
together in an ASP. I'm using VBScript.
What I'm trying to achieve is this -
- Page loads up and some server side vbscript reads the database and
populates a listbox on the page with the first field from each record
in the recordset. This works fine.
- User selects an option on the listbox and, using the OnChange, I
|
by: Jeff Thies |
last post by:
I'd like to randomly sort an array. A good method?
|
by: rdlebreton |
last post by:
Hi, Folks!
I've been trying to develop my own version of these draggable
layers and I have been limiting myself to IE6...for now. I have
looked at some other examples to get ideas of creating an alternative
to pop-up windows in a web page. The code I have works (sort of).
The problem is that I can move these layers around when I move the
mouse slowly, however, if I move it fast the web browser looses track
of the motion and leaves the...
|
by: Jim Lewis |
last post by:
I'm trying to move a function into pyrex for speed. The python side
needs to pass a list to the pyrex function. Do I need to convert to
array or something so pyrex can generate tight code? I'm not clear how
to do this.
| |
by: bruce |
last post by:
hi...
i'm trying to deal with multi-dimension lists/arrays
i'd like to define a multi-dimension string list, and then manipulate the
list as i need... primarily to add lists/information to the 'list/array' and
to compare the existing list information to new lists
i'm not sure if i need to import modules, or if the base python install i
have is sufficient. an example, or pointer to examples would be good...
|
by: Tobiah |
last post by:
I checked out the array module today. It claims that
arrays are 'efficient'. I figured that this must mean
that they are faster than lists, but this doesn't seem
to be the case:
################ one.py ##############
import array
a = array.array('i')
|
by: pereges |
last post by:
Hi, I am wondering which of the two data structures (link list or
array) would be better in my situation. I have to create a list of
rays for my ray tracing program.
the data structure of ray looks like this:
typedef struct
{
vector origin; /* vector is an array of 3 doubles */
|
by: Jillian Calderon |
last post by:
Hi.
How do I define a 2d list?
For instance, to define a 4 by 5 list, I wanted to do this:
n=4
m=5
world =
However, it gives me an invalid syntax error saying the index is out
of range.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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,...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |