473,320 Members | 1,990 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,320 software developers and data experts.

generic toarray string[] ?

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");
string.Join("','", (string[])al.ToArray(typeof(string)));

but with generic :
List<Guidguid = new List<Guid>();
guid.Add(new Guid( /(..)/ ));
guid.Add(new Guid( /(..)/ ));
guid.Add(new Guid( /(..)/ ));
?? string.Join("','", (string[])guid.ToArray()); ??

thanks
Oct 16 '07 #1
1 4506
On Oct 16, 10:21 am, Steph <st...@pipoland.comwrote:
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");
string.Join("','", (string[])al.ToArray(typeof(string)));
Yes, that's converting a list of strings into an array of strings.
but with generic :
List<Guidguid = new List<Guid>();
guid.Add(new Guid( /(..)/ ));
guid.Add(new Guid( /(..)/ ));
guid.Add(new Guid( /(..)/ ));
?? string.Join("','", (string[])guid.ToArray()); ??
That's trying to convert a list of Guids into an array of strings -
that's not going to work, and it wouldn't have worked if you'd had an
ArrayList of Guids either.

You could use List<Guid>.ConvertAll<stringand specify a delegate
which just calls ToString() on the Guid, then call ToArray.

Jon

Oct 16 '07 #2

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

Similar topics

6
by: Urs Eichmann | last post by:
While experimenting with the Feb CTP Edition of VB 2005, I came across "generic procedures". You can write: Public Class Foo Public Sub MySub(Of tDisp As IDisposable)(ByVal vMyParm As Integer)...
2
by: Richard Bysouth | last post by:
I'm sure this is something pretty trivial but can't seem to figure out how to do it. I'm using Generic Lists in quite a few places in my app and for some of them want to be able to create a...
22
by: Adam Clauss | last post by:
OK, I have class A defined as follows: class A { A(Queue<B> queue) { ... } } Now, I then have a subclass of both classes A and B. The subclass of A (SubA), more specifically is passed a...
3
by: shapper | last post by:
Hello, I have a Generic.List and I need to create a string out of it. Something like: "Item1, Item2, Item 3, ItemN" How can I do this? Thanks, Miguel
5
by: =?Utf-8?B?TWFya0F1cml0?= | last post by:
I need to output a Generic List to an array, but Ive been unable to. The list looks like: List<Employeeemp = new List<Employee>(); When I use ToArray() with it: string empArray =...
3
by: ndac | last post by:
Hello, assume I have the following: public interface X<E{ ... E toArray(); } public class XImp<E{ E toArray(){
3
by: shapper | last post by:
Hello, How can I convert a Generic.List(Of String) to a single string where all elements are separated by a comma? My string would become: "item1,item2,item3" Thanks,
4
by: mojeza | last post by:
I would like to create generic object which will be used for store of single row of DataTable. Lets say I create class as follow: Public Class Participant Public ParticipantID As Int64 Public...
9
by: timor.super | last post by:
Hi group, please look at my generic method : static void Write<T>(IEnumerable<IEnumerable<T>list) { foreach (IEnumerable<Tts in list) { foreach (T t in ts) {
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.