Use of Params in C# and ParamArray in VB.Net

Posted by vishalneeraj-24503 under ASP.NET category on | Points: 40 | Views : 3464
Today, we will learn about working with Params/ParamArray in DotNet,

As we know that, Params let us know methods to pass variable numbers of parameters. We pass a comma-separated values to params array.

Note:- 1).ParamArray will always be defined as a Last parameters in Method definition.
2). In C#, it is pronounced as params
3). In, it is pronounced as ParamArray

We can understand this by an example:-

private int calculate_values(params int[] values)
int total = 0;

foreach (int value in values)
total+ = value;
catch(Exception ex)
throw ex;
return total;

public static void main(string[] args)
int total1 = calculate_values(1,2);
int total2 = calculate_values(1,2,3);
int total3 = calculate_values(1,2,3,10);

//Output will be

In VB.Net, we can define ParamArray as

Private Function calculate_values(ByVal ParamArray values() As Integer) As Integer
//do same code here
End Function

Comments or Responses

Posted by: t5j9033387989 on: 11/26/2013 Level:Starter | Status: [Member] | Points: 10

Login to post response