Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Format IEnumerable<string> overload
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesqo committed Nov 21, 2016
1 parent 5e9f536 commit c5c9f55
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/mscorlib/src/System/String.Manipulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -651,31 +651,39 @@ public unsafe static string Join<T>(string separator, IEnumerable<T> values)
}

[ComVisible(false)]
public static String Join(String separator, IEnumerable<String> values) {
public static string Join(string separator, IEnumerable<string> values)
{
if (values == null)
{
throw new ArgumentNullException(nameof(values));
Contract.Ensures(Contract.Result<String>() != null);
Contract.EndContractBlock();
}

using(IEnumerator<String> en = values.GetEnumerator()) {
using (IEnumerator<string> en = values.GetEnumerator())
{
if (!en.MoveNext())
return String.Empty;
{
return string.Empty;
}

String firstValue = en.Current;
string firstValue = en.Current;

if (!en.MoveNext()) {
if (!en.MoveNext())
{
// Only one value available
return firstValue ?? String.Empty;
return firstValue ?? string.Empty;
}

// Null separator and values are handled by the StringBuilder
StringBuilder result = StringBuilderCache.Acquire();
result.Append(firstValue);

do {
do
{
result.Append(separator);
result.Append(en.Current);
} while (en.MoveNext());
}
while (en.MoveNext());

return StringBuilderCache.GetStringAndRelease(result);
}
}
Expand Down

0 comments on commit c5c9f55

Please sign in to comment.