////// Concatenates a specified separator String between each element of a specified enumeration, yielding a single concatenated string. /// ///any object /// The enumeration /// A String ///A String consisting of the elements of value interspersed with the separator string. public static string ToString(this IEnumerable list, string separator) { StringBuilder sb = new StringBuilder(); foreach (var obj in list) { if (sb.Length > 0) { sb.Append(separator); } sb.Append(obj); } return sb.ToString(); }
Monday, January 30, 2012
Best Extension Methods: From IEnumerable To String
This extension method creates a string with specified separator from an IEnumerable List.
Share This!
Labels:
C#.NET,
Extension Methods
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment