IT Community - Software Programming, Web Development and Technical Support

Converting a generics List<T> to string[]

This is a discussion on Converting a generics List<T> to string[] within the C# Programming forums, part of the Software Development category; Is there any easy way to convert a List<T>containing string data to string[]? I'm trying ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 12-21-2007, 03:24 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Converting a generics List<T> to string[]

Is there any easy way to convert a List<T>containing string data to string[]?

I'm trying to convert some sample code from using Enums.
__________________
The OXYGEN
Delivers edgy, intelligent Technology to all...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-21-2007, 03:26 AM
Balasubramanian.S Balasubramanian.S is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 182
Balasubramanian.S is on a distinguished road
Default Re: Converting a generics List<T> to string[]

I am pretty sure you can do the following

string[] bar = (string[])list1.ToArray (typeof(string));

Where list1 is your List<string>

I hope that helps,
__________________
S.Balasubramanian
Nothing is impossible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-21-2007, 03:28 AM
Balasubramanian.S Balasubramanian.S is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 182
Balasubramanian.S is on a distinguished road
Default Re: Converting a generics List<T> to string[]

hi,

can you try something like following
List<string> li =new List<string>();

li.Add("list1");
li.Add("list1");

li.Add("list2");
li.Add("list3");

string[] si = li.ToArray();

Response.Write(si[0]);
__________________
S.Balasubramanian
Nothing is impossible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 12-21-2007, 03:33 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: Converting a generics List<T> to string[]

I have a list of something other than strings, then how to convert it into string array? Can you give me any idea?
__________________
The OXYGEN
Delivers edgy, intelligent Technology to all...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 12-21-2007, 03:34 AM
Balasubramanian.S Balasubramanian.S is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 182
Balasubramanian.S is on a distinguished road
Default Re: Converting a generics List<T> to string[]

Hi,

Use this to retrieve other than string.

List myList = new List();
// populate myList;
string[] myStringArray = myList.ConvertAll<string>(delegate(int ii) { return ii.ToString(); }).ToArray();
__________________
S.Balasubramanian
Nothing is impossible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting image from one format to another in C# Sathish Kumar C# Programming 24 06-04-2008 02:06 AM
Compare a string with String Array. oxygen C# Programming 5 12-28-2007 11:18 PM
What is diffrenece between string.compare and string.compareordinal shaalini ASP and ASP.NET Programming 3 12-28-2007 10:46 PM
Converting Nikon camera RAW images to JPEG,TIFF files using Adobe dll in C#.NET oxygen C# Programming 5 08-16-2007 03:26 AM
How to split a string by using a string usually in the c# dotnet... Archer C# Programming 1 07-25-2007 03:26 AM


All times are GMT -7. The time now is 02:33 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0