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<Guid> guid = new List<Guid>();
guid.Add(new Guid( /(..)/ ));
guid.Add(new Guid( /(..)/ ));
guid.Add(new Guid( /(..)/ ));
?? string.Join("','", (string[])guid.ToArray()); ??
thanks
> hello, i ve tries to convert a generic into a string[] for use string.join.
>
[quoted text clipped - 4 lines]
> 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<Guid> guid = 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<string> and specify a delegate
which just calls ToString() on the Guid, then call ToArray.
Jon