using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Diagnostics;
public static void Main(string[] args)
var stopwatch = new Stopwatch();
str = AppendFunc("", ", ", "hello", "world", "", "Test");
Console.WriteLine("linq: " + str + " - "+ stopwatch.ElapsedTicks);
var stopwatch2 = new Stopwatch();
str = AppendFunc2("", ", ", "hello", "world", "", "Test");
Console.WriteLine("conventional: " + str + " - "+ stopwatch2.ElapsedTicks);
public static string AppendFunc(string str, string separator, params string[] values) {
str = str ?? string.Empty;
if (!string.IsNullOrEmpty(str)) {
str += ", " + String.Join(separator, values.Where(s => !string.IsNullOrEmpty(s)));
str = String.Join(separator, values.Where(s => !string.IsNullOrEmpty(s)));
public static string AppendFunc2(string str, string separator, params string[] values) {
str = str ?? string.Empty;
foreach (string value in values)
if (!string.IsNullOrEmpty(value))