ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

join

--

Source

public static string join<T>(this IEnumerable<T> list, string separator)
{
	string s = "";
	foreach (object x in list) {
		s += x.ToString() + separator;
	}
	return (s.Length > separator.Length) ?
		s.Remove(s.Length - separator.Length) : String.Empty;
}

Example

List<string> fruits = new List() { "Apple", "Banana", "Citron" }; fruits.join(", "); //=> "Apple, Banana, Citron"

Author: Thomas Kowalski

Submitted on: 20 feb. 2009

Language: C#

Type: System.Collections.Generic.IEnumerable<T>

Views: 5249