Create comma separated strings C#?

前端 未结 5 1528
走了就别回头了
走了就别回头了 2020-12-09 01:22

I have an object which holds many values, some of them (not all values from the object) need to be put in a csv string. My approach was this:

string csvStrin         


        
5条回答
  •  没有蜡笔的小新
    2020-12-09 01:52

    If you put all your values in an array, at least you can use string.Join.

    string[] myValues = new string[] { ... };
    string csvString = string.Join(",", myValues);
    

    You can also use the overload of string.Join that takes params string as the second parameter like this:

    string csvString = string.Join(",", value1, value2, value3, ...);
    

提交回复
热议问题