469,568 Members | 1,483 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,568 developers. It's quick & easy.

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 1275

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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Nick | last post: by
1 post views Thread by Jamus Sprinson | last post: by
4 posts views Thread by Hans De Schrijver | last post: by
5 posts views Thread by Pete Hearn | last post: by
1 post views Thread by Craig | last post: by
22 posts views Thread by Steven Blair | last post: by
3 posts views Thread by rn5a | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.