With the method parameter params,
you can pass any numbers of parameter returning in a Enumerable, list array etc..
With a flexible call Increment(1,2,3),
Increment(1,2),
Increment(myIntArray),
Increment(1)` ..
static IEnumerable<int> Increment(params int[] args)
{
return args.Select(x => x + 1);
}
Allowing call like :
var result = Increment(45, 30, 45, 30);
// {46, 31, 46, 31}
For the display, you can use string join. string.Join(", ", result)
static void Main(string[] args)
{
var uniqueValue = 99;
var multipleValues = new[] { 1, 2, 6 };
var uvResult = Increment(uniqueValue);
var mvResult = Increment(multipleValues);
Console.WriteLine($"uniqueValue = {uniqueValue} => {string.Join(", ",uvResult)}");
Console.WriteLine($"multipleValues = {string.Join(", ",multipleValues)} => {string.Join(", ",multipleValues)}");
}