Moved PunctuateList method to Extensions class

This commit is contained in:
AJ
2019-11-21 14:49:57 -05:00
parent df7c3061ba
commit c80020956f

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
@@ -41,5 +42,32 @@ namespace ExportDXF
return s.ToString(); return s.ToString();
} }
public static string PunctuateList(this IEnumerable<string> stringList)
{
var list = stringList.ToList();
switch (list.Count)
{
case 0:
return string.Empty;
case 1:
return list[0];
case 2:
return string.Format("{0} and {1}", list[0], list[1]);
default:
var s = string.Empty;
for (int i = 0; i < list.Count - 1; i++)
s += list[i] + ", ";
s += "and " + list.Last();
return s;
}
}
} }
} }