Skip to content

Instantly share code, notes, and snippets.

@pgsin
Created February 28, 2017 14:38
Show Gist options
  • Save pgsin/5fb86df4d88279bebe37c288d32d3a82 to your computer and use it in GitHub Desktop.
Save pgsin/5fb86df4d88279bebe37c288d32d3a82 to your computer and use it in GitHub Desktop.
BaseLibS.Utils.StringUtils.Concat
using System;
using System.Collections.Generic;
using System.Text;
namespace Test {
public class Program {
static void Main() {
Console.WriteLine(Concat(",",new List<string> {"a","b","c"}));
}
public static string Concat<T>(string separator, IEnumerable<T> o) {
if (o == null) {
return "";
}
IEnumerator<T> oe = o.GetEnumerator();
if (!oe.MoveNext()) return "";
StringBuilder s = new StringBuilder();
s.Append(oe.Current);
while (oe.MoveNext()) {
s.Append(separator + oe.Current);
}
return s.ToString();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment