15 September, 2010
0 Comments
1 category
If you want to concatenate all items in a generic List<string> in C# you can use the following code:
List<string> itemsInGenericList = new List<string> { "Item 1", "Item 2", "Item 3", "Item 4" }; // Convert generic list of strings to an array of strings. string[] itemsInArray = itemsInGenericList.ToArray(); // Convert an array of strings to one string. string itemsInString = string.Join(Environment.NewLine, itemsInArray); Console.WriteLine(itemsInString); // Convert an array of strings to a generic list of strings. itemsInGenericList = new List<string>(itemsInArray);
Result
Item 1
Item 2
Item 3
Item 4
Tags: C#
Category: Uncategorized