How to send comma separated list of numbers to a method with array as parameter in C#

1 Answer

0 votes
using System;

public class Program
{
    public static void WithParams(params int[] arr) {
        for (int i = 0; i < arr.Length; i++) {
            Console.Write(arr[i] + " ");
        }
        Console.WriteLine();
    }


    static void Main() {
        WithParams(5, 7, 0, 2, 1);
    }
}



/*
run

5 7 0 2 1 

*/

 



answered Nov 27, 2020 by avibootz

Related questions

2 answers 213 views
1 answer 197 views
1 answer 187 views
1 answer 168 views
...