string.Join on a List or other type

前端 未结 7 1573
甜味超标
甜味超标 2020-12-01 10:19

I want to turn an array or list of ints into a comma delimited string, like this:

string myFunction(List a) {
    return string.Join(\",\", a);
}
         


        
相关标签:
7条回答
  • 2020-12-01 10:50

    Had a similar Extension Method that I modified to this

    public static class MyExtensions
    {
        public static string Join(this List<int> a, string splitChar)
        {
            return string.Join(splitChar, a.Select(n => n.ToString()).ToArray());
        }
    }
    

    and you use it like this

    var test = new List<int>() { 1, 2, 3, 4, 5 };
    string s = test.Join(",");
    

    .NET 3.5

    0 讨论(0)
提交回复
热议问题