Skip to content

Instantly share code, notes, and snippets.

@karenpayneoregon
Last active January 1, 2025 04:59
Show Gist options
  • Save karenpayneoregon/33d12149c05993e8f5fe7679ceca2051 to your computer and use it in GitHub Desktop.
Save karenpayneoregon/33d12149c05993e8f5fe7679ceca2051 to your computer and use it in GitHub Desktop.
C# 13 parms
using System.Diagnostics;
using NewStuffApp.Models;
namespace NewStuffApp.Classes;
/// <summary>
/// Provides a set of static methods for iterating over collections of various types
/// (e.g., strings, integers, and Person) and performing operations on them.
/// </summary>
internal class Params
{
public static void Iterate(params IEnumerable<string> values)
{
foreach (var (index, item) in values.Index())
Debug.WriteLine($"{index,-5}{item}");
}
public static void Iterate(params IEnumerable<int> values)
{
foreach (var (index, item) in values.Index())
Debug.WriteLine($"{index,-5}{item}");
}
public static void Examples()
{
Iterate(1, 2, 3, 4, 5);
Iterate([6, 7, 8]);
Iterate("Sam", "Anne", "Mary", "Dan", "Kim");
Iterate(["Jim", "Tony", "Lisa"]);
}
}
internal class Person
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment