473,785 Members | 2,488 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

copying an arraylist of objects into an array of the objects themselves.

If this makes sense, I would like to convert an arraylist of objects
returned from foo() into an array of the objects themselves per;

private Customer[] customers;
private int idx = 0;

public CustomerQueueSe rvice()
{
customers = new Customer[] ;
customers = foo(); //I want to copy the returned arraylist
of Customer(s) into the array of Customer(s)
}

public ArrayList foo() {
ArrayList arr = new ArrayList();
while (dr.Read())
{
Customer oCust = new Customer();

if (!dr.IsDBNull(0 )) { oCust.CustomerI d = dr.GetInt32(0); }
if (!dr.IsDBNull(1 )) { oCust.OtherId = dr.GetInt32(1); }
arr.Add(oCust);
}
return arr;
}

Thank you,
-hazz
Nov 18 '05 #1
5 1402

ToArray()?
--
Robert Jeppesen
Durius
http://www.durius.com/

"hazz" <hazz@sonic_net > wrote in message
news:e4******** ******@TK2MSFTN GP15.phx.gbl...
If this makes sense, I would like to convert an arraylist of objects
returned from foo() into an array of the objects themselves per;

private Customer[] customers;
private int idx = 0;

public CustomerQueueSe rvice()
{
customers = new Customer[] ;
customers = foo(); //I want to copy the returned
arraylist of Customer(s) into the array of Customer(s)
}

public ArrayList foo() {
ArrayList arr = new ArrayList();
while (dr.Read())
{
Customer oCust = new Customer();

if (!dr.IsDBNull(0 )) { oCust.CustomerI d = dr.GetInt32(0); }
if (!dr.IsDBNull(1 )) { oCust.OtherId = dr.GetInt32(1); }
arr.Add(oCust);
}
return arr;
}

Thank you,
-hazz

Nov 18 '05 #2
Take a look at class ArrayList's CopyTo method.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"hazz" wrote:
If this makes sense, I would like to convert an arraylist of objects
returned from foo() into an array of the objects themselves per;

private Customer[] customers;
private int idx = 0;

public CustomerQueueSe rvice()
{
customers = new Customer[] ;
customers = foo(); //I want to copy the returned arraylist
of Customer(s) into the array of Customer(s)
}

public ArrayList foo() {
ArrayList arr = new ArrayList();
while (dr.Read())
{
Customer oCust = new Customer();

if (!dr.IsDBNull(0 )) { oCust.CustomerI d = dr.GetInt32(0); }
if (!dr.IsDBNull(1 )) { oCust.OtherId = dr.GetInt32(1); }
arr.Add(oCust);
}
return arr;
}

Thank you,
-hazz

Nov 18 '05 #3
Thank you Robert!

return (Customer[])arr.ToArray(ty peof(Customer)) ;
"Robert Jeppesen durius (dot) com>" <robert<at> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..

ToArray()?
--
Robert Jeppesen
Durius
http://www.durius.com/

"hazz" <hazz@sonic_net > wrote in message
news:e4******** ******@TK2MSFTN GP15.phx.gbl...
If this makes sense, I would like to convert an arraylist of objects
returned from foo() into an array of the objects themselves per;

private Customer[] customers;
private int idx = 0;

public CustomerQueueSe rvice()
{
customers = new Customer[] ;
customers = foo(); //I want to copy the returned
arraylist of Customer(s) into the array of Customer(s)
}

public ArrayList foo() {
ArrayList arr = new ArrayList();
while (dr.Read())
{
Customer oCust = new Customer();

if (!dr.IsDBNull(0 )) { oCust.CustomerI d =
dr.GetInt32(0); }
if (!dr.IsDBNull(1 )) { oCust.OtherId = dr.GetInt32(1); }
arr.Add(oCust);
}
return arr;
}

Thank you,
-hazz


Nov 18 '05 #4
Thank you Peter!

return (Customer[])arr.ToArray(ty peof(Customer)) ; is just what I need.
"Peter Bromberg [C# MVP]" <pb*******@yaho o.nospammin.com > wrote in message
news:FE******** *************** ***********@mic rosoft.com...
Take a look at class ArrayList's CopyTo method.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"hazz" wrote:
If this makes sense, I would like to convert an arraylist of objects
returned from foo() into an array of the objects themselves per;

private Customer[] customers;
private int idx = 0;

public CustomerQueueSe rvice()
{
customers = new Customer[] ;
customers = foo(); //I want to copy the returned
arraylist
of Customer(s) into the array of Customer(s)
}

public ArrayList foo() {
ArrayList arr = new ArrayList();
while (dr.Read())
{
Customer oCust = new Customer();

if (!dr.IsDBNull(0 )) { oCust.CustomerI d =
dr.GetInt32(0); }
if (!dr.IsDBNull(1 )) { oCust.OtherId = dr.GetInt32(1); }
arr.Add(oCust);
}
return arr;
}

Thank you,
-hazz

Nov 18 '05 #5
I fear we may have lost him in ArrayLand...
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Robert Jeppesen durius (dot) com>" wrote:

ToArray()?
--
Robert Jeppesen
Durius
http://www.durius.com/

"hazz" <hazz@sonic_net > wrote in message
news:e4******** ******@TK2MSFTN GP15.phx.gbl...
If this makes sense, I would like to convert an arraylist of objects
returned from foo() into an array of the objects themselves per;

private Customer[] customers;
private int idx = 0;

public CustomerQueueSe rvice()
{
customers = new Customer[] ;
customers = foo(); //I want to copy the returned
arraylist of Customer(s) into the array of Customer(s)
}

public ArrayList foo() {
ArrayList arr = new ArrayList();
while (dr.Read())
{
Customer oCust = new Customer();

if (!dr.IsDBNull(0 )) { oCust.CustomerI d = dr.GetInt32(0); }
if (!dr.IsDBNull(1 )) { oCust.OtherId = dr.GetInt32(1); }
arr.Add(oCust);
}
return arr;
}

Thank you,
-hazz


Nov 18 '05 #6

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

Similar topics

3
322
by: Nick | last post by:
Hi ! I have Objects in my ArrayList These Objects contain a String called "Name". And i want that ArrayList to sort it's objects using the Name element of each object and not something else of the object ?!? I think this is somehow accomplished using the Comparer class, but i have not checked it out yet.
1
4626
by: Jamus Sprinson | last post by:
Before I continue, I'm going to begin by saying I'm not by any means an expert- I've been using .NET with C# for about 4 months now, and basically just learning by example and docs. A game project I work on uses Xml serialization to store game objects for loading. One of the techniques we use is to make an array property and use the set block to perform actions on the values after they're loaded from the xml, as in: public string Ids
4
1718
by: Hans De Schrijver | last post by:
I have a private ArrayList variable that holds objects of various types, though they're all derived from a common base class (User). What I would like to do is provide public accessor properties per type. I have written some code that does the trick now, but it involves looping through the private ArrayList and creating a new Array with just the objects of the type corresponding to the property. Problem is, this hapens every time you...
5
10959
by: Pete Hearn | last post by:
Hello All, New to the whole C#/Webservice/ADO.NET thing, so apologies in advance if this is a daft question! I have a webservice which returns a dataset - no problem there and all very standard. However, I want to pass an arraylist of objects to the method which returns the dataset (the arraylist contains QBE parameter objects) but the compiler chokes saying it wants an object array instead.
1
5745
by: Craig | last post by:
Hey Everyone - I'm trying to determine the fastest way of moving array information around and could use some help. Here's the setup: Class A stores a DateTime and an amount (a payment). Class B is functionally an array of A objects (representing a cashflow). Class C is functionally an array of B objects (representing an organization of cashflows).
18
4750
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the class where only the "searched" property has a value. I expected to get the index into the arraylist where I could then get the entire class instance. However, the 'indexof' is never calling my overloaded, overrides Equals method. Here is the...
10
8514
by: chrisben | last post by:
Hi, Here is the scenario. I have a list of IDs and there are multiple threads trying to add/remove/read from this list. I can do in C# 1. create Hashtable hList = Hashtable.Synchronized(new Hashtable()); 2. create ArrayList aList = ArrayList.Synchronized(new ArrayList()); 3. create a string sList = ""; For 1 and 2, since the list is synced, many threads can directly
22
15948
by: Steven Blair | last post by:
I need to perform a Deep Copy on an ArrayList. I wrote a small sample app to prove this could be done: ArrayList a = new ArrayList(); ArrayList b = new ArrayList(); a.Add("Hello"); b = (ArrayList) a.Clone();
3
1733
by: rn5a | last post by:
What's wrong with the following code? Dim arrColors(5) As ArrayList arrColors(5) = New ArrayList arrColors(0).Add("Red") arrColors(1).Add("Blue") arrColors(2).Add("Green") arrColors(3).Add("Yellow") arrColors(4).Add("Black")
0
9480
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,...
0
10325
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...
1
10091
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
9950
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
8972
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...
1
7499
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 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...
0
6739
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();...
0
5381
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...
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.