0

On each looping, I get a value for that field. I want to store all values using comma separated in the variable (String).

var result= string.Empty;
foreach (var details in Response)
{
    result+= details.name;
}

Example data I am want:

result = "abc, de123, 15R2W" ;

while current code collapses all into one big string: "abcde12315R2W"

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
Jasmine
  • 5,186
  • 16
  • 62
  • 114

2 Answers2

1

You can use string.Join and some Linq,

var result = string.Join(",", details.Select(x => x.name));

The Select will pull out the name string values and Join will concatenate them with a comma separating them.

juharr
  • 31,741
  • 4
  • 58
  • 93
-2

Try this:

var result = "";
foreach (var details in Response)
{
    result+= details.name + ",";
}
result = result.Substring(0,result.length-1)