For details see Calling methods is easier and faster with C# 13 params collections
Last active
January 1, 2025 04:59
-
-
Save karenpayneoregon/33d12149c05993e8f5fe7679ceca2051 to your computer and use it in GitHub Desktop.
C# 13 parms
This file contains 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
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"]); | |
} | |
} |
This file contains 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
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