Use params to mark a parameter : Variable Length Parameters : Language Basics C# Examples


C# Examples » Language Basics » Variable Length Parameters »

 

Use params to mark a parameter









    
using  System;
using  System.Collections.Generic;
using  System.Text;



class  Program  {
        static  int  SumVals(params  int[]  vals)  {
                int  sum  =  0;
                foreach  (int  val  in  vals)  {
                        sum  +=  val;
                }
                return  sum;
        }

        static  void  Main(string[]  args)  {
                int  sum  =  SumVals(1,  5,  2,  9,  8);
                Console.WriteLine("Summed  Values  =  {0}",  sum);

        }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Language Basics
» Variable Length Parameters