Tuesday, 3 January 2012

How to use PARAMS in C#

PARAMS - is used to pass number of parameter of same data type to method .


such as
public static int Addition( params int[] nums)
{
int ans ;
  for(int i=0;i<nums.length;i++)
{
 ans +=nums[i] ;
}
return ans ;
}


void main()
{
   int result = Additon( 17,45,565,34,45)   ;  // pass any number of int parameter .
        Consol.WriteLine(result);


}

No comments:

Post a Comment