Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Join with And
public static string Join<TItem>(IEnumerable<TItem> items, string separator = ", ", string end = " and ")
{
var builder = new StringBuilder();
using (var enumerator = items.GetEnumerator())
{
if (enumerator.MoveNext())
{
var item = enumerator.Current;
if (enumerator.MoveNext())
{
builder.Append(item);
item = enumerator.Current;
while (enumerator.MoveNext())
{
builder.Append(separator);
builder.Append(item);
item = enumerator.Current;
}
builder.Append(end);
}
builder.Append(item);
}
}
return builder.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.