C # params keyword

Source: Internet
Author: User

Key points of the params array

The params in the C # development language is a keyword that can specify method parameters that take parameters at variable number of arguments. Useful when the number of arguments to a function is variable and the code being executed is very small!

1 class Program2 {3     Static voidMain (string[] args)4      {5Sum (1,2,"a");6       Console.readkey ();7      }8 Static voidSum (params Object[] numstack)9 {Ten      for(inti =0; i < numstack.length; i++) One      { A       Console.WriteLine (Numstack[i]); -      } -     } the}

The 1.params keyword cannot be used on multidimensional arrays.

1  Public Static Min (paramsint[,],table)...  

2. You cannot use the overloaded method with only the params.

1  Public Static int Min (int[] paramlist)
2  Public Static int Min (paramsint

3 The ref and out pass params are not allowed to be used simultaneously

1  Public Static int Min (refparamsint[] paramlist)
... 2 Public Static int Min (outparamsint[] paramlist)
......

4.params array must be the last parameter

1  Public Static int Min (paramsint[] paramlist,int i)//error

5. No params method priority is higher than the priority with the params method

1  Public Static int Min (int lefthandside,int  righthandside)2publicstatic  int Min (paramsint[] paramlist)

C # params keyword

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.