.NET 4.0 New Feature - String.Join
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { String[] stringCollection = { “123”, “456”, “789” }; int[] intCollection = { 123, 456, 789 }; Object[] objCollection = { 123, “456”, 789.0f }; float[] floatCollection = { 123.0f, 456.0f, 789.0f };
ShowValue<String>("stringCollection", stringCollection);
ShowValue<int>("intCollection", intCollection);
ShowValue<Object>("objCollection", objCollection);
ShowValue<float>("floatCollection", floatCollection);
}
static void ShowValue<T>(string title, IEnumerable<T> values)
{
Console.WriteLine("{0}: {1}", title, string.Join(",", values));
}
}
}
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { String[] stringCollection = { “123”, “456”, “789” }; int[] intCollection = { 123, 456, 789 }; Object[] objCollection = { 123, “456”, 789.0f }; float[] floatCollection = { 123.0f, 456.0f, 789.0f };
Console.WriteLine("{0}: {1}", "stringCollection", stringCollection.Join(","));
Console.WriteLine("{0}: {1}", "intCollection", intCollection.Join(","));
Console.WriteLine("{0}: {1}", "objCollection", objCollection.Join(","));
Console.WriteLine("{0}: {1}", "floatCollection", floatCollection.Join(","));
}
}
public static class IEnumerableExtension
{
public static string Join<T>(this IEnumerable<T> obj, string seperator)
{
return string.Join(seperator, obj);
}
}
}