473,657 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(typ eof(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 4532
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(typ eof(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>.Conv ertAll<stringan d 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
2773
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) End Sub
2
3553
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 ToString method that would return a formatted string array. For example, I might have a simple class as follows: Class Foo
22
13105
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 Queue<SubB>.
3
397
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
18168
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 = emp.ToArray(); I get the error message: Cannot implicitly convert type 'NgItIts.AD2Service.Ad2Employee' to 'string'
3
7306
by: ndac | last post by:
Hello, assume I have the following: public interface X<E{ ... E toArray(); } public class XImp<E{ E toArray(){
3
407
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
2166
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 LastName As String Public FirstName As String End Class then I get a data from the database to DataTable and create array of
9
4473
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
8411
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8613
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6176
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.