0

could someone remind me the rules of params.

is it... the params method needs to be the last one and you can have only params as the parameter in the method and nothing else?

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Momerath
0

params must be last, and only one params statement in a method. You can have any number of other parameters to the method as you want, they just must be before the params statement

0
class Program
    {
        static void Main(string[] args)
        {
            Foo(2, 5, 4, 3, 8, 7, 6);
            Foo(new int[] { 2, 5, 6, 7, 4, 3, 3, });

            Foo1(new int[] { 2, 5, 6, 7, 4, 3, 3, });
            Foo2("dor", 2.9, 5, 5, 4, 2, 5, 2, 5);
        }
        static void Foo(params int[] x)
        {
            for (int i = 0; i < x.Length; i++)
            {
                Console.WriteLine(x[i]);
            }
        }
        static void Foo1(int[] x)
        {

        }
        static void Foo2(string s, double d, int i, params int[] x)
        {
            Console.WriteLine("I = "+i);
        }
         //static void Foo2(params int[] x ,string s){

         //}
    }]

is the last method legit?

Edited by NewOrder: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.