List of objects, get a delimited property

public class Person { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } } 

I have a list:

 List<Person> list = new List<Person>(); 

I would like to get the Id value of all entries in a comma separated list, for example: id1, id2, id3

+4
source share
1 answer

Use string.Join to combine the values ​​and Enumerable.Select with the selected desired values:

 string allIds = string.Join(", ", list.Select(i => i.Id.ToString())); 
+12
source

All Articles