473,395 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

use ToArray function in ArrrayList

Dear all

I want to know that how to use ToArray function in ArrayList. I have an ArrayList which is storing string, Actually, I want to use the Join method, so I think I need to convert the arraylist to array first. The question is do I need to convert the arraylist to array in order to use the Join method? If so, please advise how to convert??

Million Thanks
Nov 15 '05 #1
2 2821
Hi Grey,

Something like this:

string[] myStrings = myArrayList.ToArray(typeof(string));

string allStrings = String.Join(",", myStrings);

Joe
--
http://www.csharp-station.com
"Grey" <er*****@i-cable.com> wrote in message news:Oc**************@tk2msftngp13.phx.gbl...
Dear all

I want to know that how to use ToArray function in ArrayList. I have an ArrayList which is storing string, Actually, I want to use the Join method, so I think I need to convert the arraylist to array first. The question is do I need to convert the arraylist to array in order to use the Join method? If so, please advise how to convert??

Million Thanks
Nov 15 '05 #2
Joe Mayo <jm***@nospamAtCSharpDashStation.com> wrote:
Something like this:

string[] myStrings = myArrayList.ToArray(typeof(string));


Slight error here - ArrayList.ToArray is declared to return Array, so
you need to cast:

string[] myStrings = (string[]) myArrayList.ToArray(typeof(string));

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3

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

Similar topics

2
by: Mark Oueis | last post by:
ArrayList arrayList = new ArrayList(); foreach (Blabla bla in Blablas) { arrayList.Add(Convert.ToInt32(blabla.something)); } so far this works great.. but now
2
by: Sunny | last post by:
Hi, I have a small function, that returns a string, inside the function, there is an arraylist, being processed. At the end of the function all the elements of the ArrayList are copied to my...
4
by: Derrick | last post by:
If i have an ArrayList, add a bunch of MyClass classes to it, how do I get a MyClass out of it? I've tried: MyClass clses = ArrayList.ToArray(typeof(MyClass)); but get errors about not being...
3
by: troy anderson | last post by:
I have a System.Collections.Queue instance filled with floats and I would like to convert it into a float because a third party plotting package requires it. I have tried casting Queue.ToArray()...
4
by: Peter Kirk | last post by:
Hi I call a method which returns an IList containing a list of one type of object. How do I best convert this IList to an array? I can see that the ArrayList class has a ToArray() method - but...
2
by: Dirk | last post by:
Hello The following code does not work ArrayList __gc* allControls = new ArrayList(); ..... // put some Controls in allControls .... Control __gc* arr = dynamic_cast<Control...
1
by: Tedmond | last post by:
Dear all, How can I convert a list of items from ArrayList into an array of non system type objects? e.g. The following codes have error: public class myClass { int i;
1
by: Steph | last post by:
hello, i ve tries to convert a generic into a string for use string.join. no problems with arraylist : ArrayList al = new ArrayList(); al.Add("J1"); al.Add("J2"); al.Add("J3");...
3
by: Michael Howes | last post by:
I have many double that each have a few thousand numbers in them. I need to concatenate groups of these double arrays into a new set of double. I don't know the total # of points. I thought it...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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...

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.