Skip to content

Instantly share code, notes, and snippets.

@AnthonyGiretti
Last active April 6, 2025 21:53
Show Gist options
  • Save AnthonyGiretti/431aef814c8c38b0d7def2cba399d3be to your computer and use it in GitHub Desktop.
Save AnthonyGiretti/431aef814c8c38b0d7def2cba399d3be to your computer and use it in GitHub Desktop.
C# 13 custom params that implements IEnumerable<T>
void Log(params MyCustomLogCollection logs)
{
foreach (var log in logs)
Console.WriteLine(log);
}
public class MyCustomLogCollection : IEnumerable<string>
{
private readonly List<string> _logs = new();
public void Add(string log) => _logs.Add(log);
public IEnumerator<string> GetEnumerator() => _logs.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
Log("Info", "Warning", "Error");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment