How to use array as a parameter to method with dynamic number of arguments in C#

1 Answer

0 votes
using System;

class Program
{
    static void Display(params int[] arr) {
        foreach (int n in arr)
            Console.Write($"{n}\t");
        Console.WriteLine();
    }
    
    static void Main() {
        Display(1, 2, 3, 4, 5, 6);
        
        Display(56, 87, 12, 98);
    }
}




/*
run:

1	2	3	4	5	6	
56	87	12	98			

*/

 



answered Dec 12, 2020 by avibootz

Related questions

...