Skip to content

Instantly share code, notes, and snippets.

@kamiyaowl
Created March 10, 2014 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamiyaowl/9469765 to your computer and use it in GitHub Desktop.
Save kamiyaowl/9469765 to your computer and use it in GitHub Desktop.
c#ListのtoString拡張
namespace kamiya.util{
public static class Extensions {
public static string ToString<T>(this List<T> list,Func<T,string> toStr = null,string format = "{0},"){
//default
if (toStr == null) toStr = (t) => t.ToString();
var strs = (from p in list select (toStr(p))).ToArray();
var sb = new StringBuilder("[");
foreach (var str in strs) {
sb.AppendFormat(format, str);
}
sb.AppendLine("]");
return sb.ToString();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment