Last active
April 6, 2025 21:53
-
-
Save AnthonyGiretti/431aef814c8c38b0d7def2cba399d3be to your computer and use it in GitHub Desktop.
C# 13 custom params that implements IEnumerable<T>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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