473,473 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Create 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 CustomerQueueService()
{
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.CustomerId = 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 1383

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

"hazz" <hazz@sonic_net> wrote in message
news:e4**************@TK2MSFTNGP15.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 CustomerQueueService()
{
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.CustomerId = 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 CustomerQueueService()
{
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.CustomerId = 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(typeof(Customer));
"Robert Jeppesen durius (dot) com>" <robert<at> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...

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

"hazz" <hazz@sonic_net> wrote in message
news:e4**************@TK2MSFTNGP15.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 CustomerQueueService()
{
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.CustomerId =
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(typeof(Customer)); is just what I need.
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:FE**********************************@microsof t.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 CustomerQueueService()
{
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.CustomerId =
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**************@TK2MSFTNGP15.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 CustomerQueueService()
{
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.CustomerId = 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
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...
1
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...
4
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...
5
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...
1
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)....
18
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...
10
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...
22
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 =...
3
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")...
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,...
1
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...
1
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
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.