c# list to comma separated string where condition code example

Example 1: c# list to string comma separated

IList<string> strings = new List<string>{"1","2","testing"};
string joined = string.Join(",", strings);

Example 2: convert string list to comma separated string c#

Person[] people = {
        new Person(){ FirstName="Steve", LastName="Jobs"},
        new Person(){ FirstName="Bill", LastName="Gates"},
        new Person(){ FirstName="Lary", LastName="Page"}
    };
 
var str = String.Join(",", people.Select(p => p.FirstName) );