C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Convert from String Array to List<t>


Posted Date: 11 Jul 2008    Resource Type: Code Snippets    Category: Collections
Author: Payal JainMember Level: Gold    
Rating: Points: 6



The following sample code will illustrate a method to convert a string array to List<t&RT;

The process of doing so is clearly explained in the comments


string[] mylist = new string[5]; //Declaring the string array;

//Assigning values to each element in the array
mylist[0] = "Hello";
mylist[1] = "how";
mylist[2] = "are";
mylist[3] = "you";
mylist[4] = "?";

//Creating a new List<T> of type <string>
List<string> StringtoList = new List<string>(mylist.Length);

//AddRange is a method of List<T> objects that enables the conversion.
//We just need to pass the reference to the array.
StringtoList.AddRange(mylist);







Responses

Author: Nishanth Nair    13 Oct 2008Member Level: Silver   Points : 1
Nice snippet. Thanks for sharing. Saved a lot of junk code.

Nishanth Nair
McAfee India


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
String array to List  .  Convert to List from array of Strings  .  Convert string array to list  .  Convert array to list  .  Convert Array of Strings to List  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Hashtable - basic operations
Previous Resource: A simple LINQ query on Collection
Return to Discussion Resource Index
Post New Resource
Category: Collections


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use