Created
March 10, 2014 17:28
-
-
Save kamiyaowl/9469765 to your computer and use it in GitHub Desktop.
c#ListのtoString拡張
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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