c# read comma separated string into list code example

Example 1: 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) );

Example 2: convert comma separated string to array c#

string fruit = "Apple,Banana,Orange,Strawberry";
string[] split = fruit.Split(',');

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

string[] animals = { "Cat", "Alligator", "Fox", "Donkey" };
var str = String.Join(",", animals);