Skip to content

Instantly share code, notes, and snippets.

@karenpayneoregon
Created August 31, 2025 09:46
Show Gist options
  • Select an option

  • Save karenpayneoregon/7ded8f2c980a385a9455794716b8821b to your computer and use it in GitHub Desktop.

Select an option

Save karenpayneoregon/7ded8f2c980a385a9455794716b8821b to your computer and use it in GitHub Desktop.
C# CommaDelimitedStringCollection
AnsiConsole.MarkupLine("[yellow]Comma delimited full month names[/]");
CommaDelimitedStringCollection result1 = [];
result1.AddRange(DateTimeFormatInfo.CurrentInfo.MonthNames[..^1]);
Console.WriteLine($"{result1}");
AnsiConsole.MarkupLine("[yellow]Using an int array[/]");
int[] items = [1, 2, 3];
CommaDelimitedStringCollection result2 = new();
result2.AddRange(items.ToStringArray());
result2.Add("4");
Console.WriteLine($"{result2}");
AnsiConsole.MarkupLine("[yellow]Using DateOnly[/]");
CommaDelimitedStringCollection results3 = [];
List<DateOnly> dates = [new(2022, 1, 1), new(2023, 2, 14), new(2024, 3, 17), new(2025, 7, 4)];
foreach (var date in dates)
{
results3.Add(date.ToString());
}
Console.WriteLine($"{results3}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment