Convert List to string with delimiter

Convert List, string. Think of a sentence. It contains some words. We could represent a sentence as a single string—one with spaces. But a list of strings (of words) is sometimes better.

EG1
var dogCsv = string.Join(",", dogs.ToArray());

EG2
var names = new List<string>() { "John", "Anna", "Monica" }; 
var result = String.Join(", ", names.ToArray());

References

Leave a Reply