Is it possible in C# to combine the Name properties of the List<Tag> object with a comma "," with a line command?
"World,Tech,Science,Arts"
public class Tag
{
public int Id { get; set; }
public string Name { get; set; }
}
List<string> tagNames;
foreach (var tag in tags)
{
tagNames.add(tag.Name);
}
string result = String.Join(",", tagNames);
I tried this but it doesn't work
string result = String.Join(",", tags.ForEach(t => t.Name));
Select, notForEachand make sure you haveusing System.Linq;List'sForEachhas done more damage for people's understanding of LINQ, than good for C# as a whole