Is there a way to make this a one liner?
List<string> ids = new List<string>(result.Count);
for(int i = 0; i < result.Count; i++)
ids.Add(i.ToString());
string reportIds = String.Join(",", ids);
I'm pretty sure there's a way with linq, but I can't figure out
string.Join()
actually takes IEnumerable<object>
in one of its overloads so there is no need to call ToString()
yourself. Here is the complete one-liner using Enumerable.Range()
:
var reportIds = string.Join(",", Enumerable.Range(0, result.Count));
string reportIds = String.Join(",",Enumerable.Range(0, result.Count));
string str = String.Join(",", Enumerable.Range(0, count).Select(n => n.ToString()));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.