Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Params - Passing multiple arguments in C#

Params allows user to give multiple arguments.(usually in array)

This is the example code for params.

Note:
Console.Write is used here instead of Console.WriteLine to give the oneline output.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6.  
  7. namespace ConsoleApplication3
  8. {
  9. class Program
  10. {
  11. static private void paramTest(string name, params int[] list)
  12. {
  13. Console.Write("\n" + name);
  14. foreach (int i in list)
  15. {
  16. Console.Write(i);
  17. }
  18. }
  19. static void Main(string[] args)
  20. {
  21. paramTest("c# param",1,2);
  22. paramTest("again", 1, 2, 3, 4, 5);
  23. }
  24. }
  25. }


  1. output:
  2. c# param12
  3. again12345